/***************************************************************
Copyright Statement:

This software/firmware and related documentation (EcoNet Software) 
are protected under relevant copyright laws. The information contained herein 
is confidential and proprietary to EcoNet (HK) Limited (EcoNet) and/or 
its licensors. Without the prior written permission of EcoNet and/or its licensors, 
any reproduction, modification, use or disclosure of EcoNet Software, and 
information contained herein, in whole or in part, shall be strictly prohibited.

EcoNet (HK) Limited  EcoNet. ALL RIGHTS RESERVED.

BY OPENING OR USING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY 
ACKNOWLEDGES AND AGREES THAT THE SOFTWARE/FIRMWARE AND ITS 
DOCUMENTATIONS (ECONET SOFTWARE) RECEIVED FROM ECONET 
AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON AN AS IS 
BASIS ONLY. ECONET EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, 
WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 
OR NON-INFRINGEMENT. NOR DOES ECONET PROVIDE ANY WARRANTY 
WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTIES WHICH 
MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE ECONET SOFTWARE. 
RECEIVER AGREES TO LOOK ONLY TO SUCH THIRD PARTIES FOR ANY AND ALL 
WARRANTY CLAIMS RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES 
THAT IT IS RECEIVERS SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD 
PARTY ALL PROPER LICENSES CONTAINED IN ECONET SOFTWARE.

ECONET SHALL NOT BE RESPONSIBLE FOR ANY ECONET SOFTWARE RELEASES 
MADE TO RECEIVERS SPECIFICATION OR CONFORMING TO A PARTICULAR 
STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND 
ECONET'S ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE ECONET 
SOFTWARE RELEASED HEREUNDER SHALL BE, AT ECONET'S SOLE OPTION, TO 
REVISE OR REPLACE THE ECONET SOFTWARE AT ISSUE OR REFUND ANY SOFTWARE 
LICENSE FEES OR SERVICE CHARGES PAID BY RECEIVER TO ECONET FOR SUCH 
ECONET SOFTWARE.
***************************************************************/

/************************************************************************
*                  I N C L U D E S
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>

#include "omci_lib_internal.h"


/************************************************************************
*                  D E F I N E S   &   C O N S T A N T S
************************************************************************/
#define IPCKEY                              (0X20160303)
#define IPCKEY_ONU                          (0X20170703)
#define IPCKEY_OMCI_INTERNAL                (0X20180803)
#define IPCKEY_RDKB							(0X20210624)


/************************************************************************
*                  M A C R O S
************************************************************************/
#define OMCI_LIB_SUCCESS	(0)
#define OMCI_LIB_FAIL	    (-1)


#define DEFAULT_MAX_PORTS			9

#define MAX_OMCI_PKT_LEN (1980)
#define MAX_OMCI_SOFTIMAGE_UPDATE_WINDOW (256)

#define GPON_EVENT_QUEUE_MAX_SIZE 128



#define LIB_GPON_NO_MSG(fmt, ...)     omci_lib_dbg_printf(OMCI_LIB_DEBUG_LEVEL_NO_MSG, fmt,##__VA_ARGS__)
#define LIB_GPON_ERROR(fmt, ...)     omci_lib_dbg_printf(OMCI_LIB_DEBUG_LEVEL_ERROR, fmt,##__VA_ARGS__)
#define LIB_GPON_WARN(fmt, ...)      omci_lib_dbg_printf(OMCI_LIB_DEBUG_LEVEL_WARN, fmt,##__VA_ARGS__)
#define LIB_GPON_TRACE(fmt, ...)     omci_lib_dbg_printf(OMCI_LIB_DEBUG_LEVEL_TRACE, fmt,##__VA_ARGS__)
#define LIB_GPON_DEBUG(fmt, ...)     omci_lib_dbg_printf(OMCI_LIB_DEBUG_LEVEL_DEBUG, fmt,##__VA_ARGS__)

#define PRINT_ARGS(fmt, ...)        

#define FUNC_TRACE_ENTER           LIB_GPON_DEBUG("[%s][%5d]===Enter===\n",__FUNCTION__,__LINE__) 

#define RETURN_FAIL_MSG(fmt, ...)   \
    do{\
        LIB_GPON_ERROR("[%s][%5d]===Fail Exit==="fmt,__FUNCTION__,__LINE__,##__VA_ARGS__); \
        return OMCI_LIB_FAIL; \
    }while(0)

#define RETURN_FAIL   \
    do{\
        LIB_GPON_ERROR("[%s][%5d]===Fail Exit===\n",__FUNCTION__,__LINE__); \
        return OMCI_LIB_FAIL; \
    }while(0)

#define RETURN_SUCCESS \
    do{\
        LIB_GPON_DEBUG("[%s][%5d]===Success Exit===\n",__FUNCTION__,__LINE__); \
        return OMCI_LIB_SUCCESS; \
    }while(0)

#define offsetofend(type,member) (offsetof(type,member)+sizeof(((type*)0)->member))
/************************************************************************
*                  D A T A   T Y P E S
************************************************************************/

#define RDKB_INVALID_GEM_ID   0xffff

typedef enum {
	/*System capability*/
	SHARED_ONU_TYPE,
	SHARED_MAX_PORTS,
	SHARED_PORT_LIST,
	SHARED_LINK_MODE,
	SHARED_EVENT_MONITOR_MASK,
	SHARED_TIME_STATUS_MSG,
	SHARED_USQ_MODE,
	
	/*ONU capability*/	
	SHARED_SN,
	SHARED_PASSWORD,
	SHARED_REGID,
	SHARED_ONU_VER,
	SHARED_TM_OPTION,
	SHARED_SURVIVAL_TIME,
	SHARED_EXT_TCLAYER,	
	
	/*ONU2 capability*/	
	SHARED_EQUIPMENT_ID,
	SHARED_VENDOR_PRO_CODE,
	SHARED_OMCC_VERSION,	
	SHARED_SECURITY_CAP,
	SHARED_TS_NUM,
	SHARED_PQ_NUM,
	SHARED_GEM_NUM,
	SHARED_SYS_UP_TIME,
	SHARED_CONNET_CAP,
	SHARED_QOS_CONF_FLEX,	
	
	/*ANI capability*/	
	SHARED_SR_INDICT,
	SHARED_TCONT_NUM,	
	SHARED_ONU_RES_TIME,
	SHARED_GEM_BLOCK_LEN,
	
	/*ONU_E capability*/
	SHARED_VENDOR_ID,	
	
	/*Enhanced security control,class ID 332*/	
	SHARED_ENHANCED_PSK,
	SHARED_ONU_SLOT,

	/*pptp video ANI init CFG*/
	SHARED_VIDEO_ANI_CFG,

	/*IPHOST MAC Address*/
	SHARED_IPHOST_MAC,
	SHARED_IPHOST_NUM,

    /*file transfer control*/
	SHARED_FILE_TRANSFER_CTRL,

	/*Authentication Security Method*/
	SHARED_AUTH_METH,

	SHARED_RXPOWER_LOWER_THRESH,
	SHARED_RXPOWER_UPPER_THRESH,
	SHARED_TXPOWER_LOWER_THRESH,
	SHARED_TXPOWER_UPPER_THRESH,
	
	SHARED_PON_TRAP_THREAD,
	
	/*Config all data*/
	SHARED_ALL_DATA,
}onu_shared_cmd_t;


typedef struct {
    pthread_rwlock_t rwlock;
	uint8_t omci_fsm_cond;
	/*ONU Capability*/	
	char 	operatorID_cap[OMCI_OPERATOR_ID_LENS];
	char 	operatorID_auth[OMCI_OPERATOR_ID_LENS];
	char 	Loid[OMCI_LOID_LENS];
	char 	LOID_Password[OMCI_LOID_PASSWORD_LENS];
	uint8_t AuthStatus;	
	uint8_t SpecVersion;
	uint8_t ONU_PowerCtr;
	uint8_t romfile_load_flag;
	uint8_t emergencyState;
	char    oltType[OMCI_OLT_TYPE_LENS];
	uint8_t selfDefVD;
	uint8_t strictPPTPEthUniSlot;
	uint8_t mibDataSyncInitVal;

	/*Others*/
	char    VoIPbyTR069;
	char    VoIPSepEn;	
    char    vlanFilterIPHostEn;
	uint16_t conReqPort;
	CompileOp_t CompileOption;
	omciAttrDefVal_t omciAttrDefVal;
    char    AESKeyMode;

	/*Debug*/
	uint8_t DebugLevel;
	uint8_t LanDebug;
	uint8_t libDbgLevel;
}omci_internal_shared_data_t;

typedef enum {
	SHARED_FSM_COND = SHARED_ALL_DATA + 1,
	/*CTC ONU Capability*/		
	SHARED_OPERATOR_ID_CAP,
	SHARED_OPERATOR_ID_AUTH,
	SHARED_LOID,
	SHARED_LOID_PASSWORD,
	SHARED_AUTH_STATUS,	
	SHARED_SPEC_VER,
	SHARED_ONU_POWER_CTRL,	
	SHARED_ROMFILE_LOAD_FLAG,
	SHARED_EMERGENCY_STATE,
	SHARED_OLT_TYPE,
	SHARED_VIOP_BY_TR069,
	SHARED_VIOP_SEP_EN,
	SHARED_CON_REQ_PORT,
	SHARED_DBG_LEVEL,
	SHARED_LAN_DBG, 
	SHARED_COMPILE_OPTION,
	SHARED_OMCI_ATTR_DEF_VAL,
	SHARED_SELF_DEF_VD,
	SHARED_STRICT_PPTP_ETHUNI_SLOT,
	SHARED_MIB_DATA_SYNC_INIT,
	SHARED_LIB_DBG_LEVEL,
	SHARED_VLAN_FILTER_IPHOST_EN,
	SHARED_UP_AES_MODE,
}onu_internal_cmd_t;

typedef struct {
	uint8_t condition;
	uint8_t condition_mask;
}omci_fsm_cond_data_t;

typedef enum{
	SHARED_VOLTAGE_MIN_VOL,
	SHARED_VOLTAGE_MAX_VOL,
	SHARED_BIAS_HIGH_BIAS,
	SHARED_TEMP_MIN_TEMP,
	SHARED_TEMP_MAX_TEMP,
	SHARED_VEIP_COUNT,
	SHARED_TR69_COUNT,
	SHARED_VEIP_LIST,
	SHARED_TR69_LIST,
	//SHARED_BCAST_VLAN,
	//SHARED_MCAST_VLAN,
	SHARED_GEM_VLAN_MAP,
	SHARED_OMCI_RESET,
}rdkb_shared_cmd_t;
/************************************************************************
*                  E X T E R N A L   D A T A   D E C L A R A T I O N S
************************************************************************/

/************************************************************************
*                  F U N C T I O N   D E F I N I T I O N S
************************************************************************/


/************************************************************************
*                  P U B L I C   D A T A
************************************************************************/

/************************************************************************
*                  P R I V A T E   D A T A
************************************************************************/

static omci_cfg_data_t *_omci_cfg_data = NULL;
static omci_internal_shared_data_t *_omci_internal_data = NULL;
static rdkb_omci_cfg_data_t * _rdkb_omci_cfg_data = NULL;

static uint8_t omci_lib_dbg_flag = OMCI_LIB_DEBUG_LEVEL_NO_MSG;

/************************************************************************
*                  F U N C T I O N   D E C L A R A T I O N S
************************************************************************/

static void reset_gem_vlan_map(){
	int i = 0, j = 0;
	for(i = 0; i < RDKB_MAX_GEM_VLAN_MAP; i++){
		_rdkb_omci_cfg_data->gemVlanMap[i].gemId= RDKB_INVALID_GEM_ID;
		_rdkb_omci_cfg_data->gemVlanMap[i].type = RDKB_GEM_TYPE_MAX;
		for(j = 0; j < RDKB_GEM_MAX_VLAN_NUM; j++){
			_rdkb_omci_cfg_data->gemVlanMap[i].vlanList[j] = RDKB_INVALID_VLAN_ID;
		}
	}
}

static int config_rdkb_shared_mem_default_data(void)
{
	FUNC_TRACE_ENTER;
	
	if (NULL == _rdkb_omci_cfg_data){
		RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	}
	_rdkb_omci_cfg_data->voltageMinVol = 3000;
	_rdkb_omci_cfg_data->voltageMaxVol = 3400;
	_rdkb_omci_cfg_data->biasHighBias = 30;
	_rdkb_omci_cfg_data->tempMinTemp = 0.0;
	_rdkb_omci_cfg_data->tempMaxTemp = 80.0;
	_rdkb_omci_cfg_data->veipEntryCount = 	0;
	_rdkb_omci_cfg_data->tr69EntryCount = 	0;
	
	memset(_rdkb_omci_cfg_data->veipList,0,sizeof(_rdkb_omci_cfg_data->veipList));
	memset(_rdkb_omci_cfg_data->tr69List,0,sizeof(_rdkb_omci_cfg_data->tr69List));
	reset_gem_vlan_map();

	RETURN_SUCCESS;
}

static int init_rdkb_omci_cfg_data(void)
{
	int shmid = -1;
    pthread_rwlockattr_t rwlattr;
    
    FUNC_TRACE_ENTER;
    
    if (NULL != _rdkb_omci_cfg_data){
        RETURN_SUCCESS;
    }

    shmid = shmget((key_t)IPCKEY_RDKB, sizeof(rdkb_omci_cfg_data_t) , 0666);
    if(-1 == shmid){
        LIB_GPON_DEBUG("RDKB SHARE MEMORY NOT CREATE!\n");
        shmid = shmget((key_t)IPCKEY_RDKB, sizeof(rdkb_omci_cfg_data_t) , 0666|IPC_CREAT);
        if(-1 == shmid){
            RETURN_FAIL_MSG("CREATE SHARE MEMORY FAILED\n");
        }
	    _rdkb_omci_cfg_data = (rdkb_omci_cfg_data_t*)shmat(shmid, (void *)0, 0);
	    if (NULL == _rdkb_omci_cfg_data){
	        RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	    }		
		memset(_rdkb_omci_cfg_data, 0, sizeof(rdkb_omci_cfg_data_t));

		config_rdkb_shared_mem_default_data();

	    /* Process Shared Read/Write lock */      
	    if(0 !=pthread_rwlockattr_init(&rwlattr)){
			goto FAIL;
	    }        
	    if(0 !=pthread_rwlockattr_setpshared(&rwlattr, PTHREAD_PROCESS_SHARED)){
			goto FAIL;
	    }    
	    if(0 !=pthread_rwlock_init(&_rdkb_omci_cfg_data->rwlock, &rwlattr)){
			goto FAIL;
    	}  
	}else {
	    _rdkb_omci_cfg_data = (rdkb_omci_cfg_data_t*)shmat(shmid, (void *)0, 0);

		if (NULL == _rdkb_omci_cfg_data){
	        RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	    }
    }    
	pthread_rwlockattr_destroy(&rwlattr);
    RETURN_SUCCESS;
	
FAIL:
	pthread_rwlockattr_destroy(&rwlattr);
	RETURN_FAIL;
}

static int get_rdkb_omci_cfg_data(rdkb_shared_cmd_t shared_cmd, void * shared_data)
{
	FUNC_TRACE_ENTER;
	int ret = OMCI_LIB_SUCCESS;

	if(NULL == shared_data){
		RETURN_FAIL_MSG("INPUT shared_data IS NULL\n");
	}

	if((NULL == _rdkb_omci_cfg_data ) && (OMCI_LIB_SUCCESS != init_rdkb_omci_cfg_data())){
        RETURN_FAIL_MSG("INIT RDKB Shared Data ERROR!\n");
    }
	pthread_rwlock_rdlock(&_rdkb_omci_cfg_data->rwlock);
	switch(shared_cmd){
	case SHARED_VOLTAGE_MIN_VOL:
		*(int*)shared_data = _rdkb_omci_cfg_data->voltageMinVol;
		break;
	case SHARED_VOLTAGE_MAX_VOL:
		*(int*)shared_data = _rdkb_omci_cfg_data->voltageMaxVol;
		break;
	case SHARED_BIAS_HIGH_BIAS:
		*(int*)shared_data = _rdkb_omci_cfg_data->biasHighBias;
		break;
	case SHARED_TEMP_MIN_TEMP:
		*(float*)shared_data = _rdkb_omci_cfg_data->tempMinTemp;
		break;
	case SHARED_TEMP_MAX_TEMP:
		*(float*)shared_data = _rdkb_omci_cfg_data->tempMaxTemp;
		break;
	case SHARED_VEIP_COUNT:
		*(int *)shared_data = _rdkb_omci_cfg_data->veipEntryCount;
		break;
	case SHARED_TR69_COUNT:
		*(int *)shared_data = _rdkb_omci_cfg_data->tr69EntryCount;
		break;
	case SHARED_VEIP_LIST:
		memcpy((omci_rdkb_veip_t *)shared_data,_rdkb_omci_cfg_data->veipList,sizeof(omci_rdkb_veip_t) * VEIP_INST_MAX_NUM);
		break;
	case SHARED_TR69_LIST:
		memcpy((omci_rdkb_tr69_t *)shared_data,_rdkb_omci_cfg_data->tr69List,sizeof(omci_rdkb_tr69_t) * TR69_INST_MAX_NUM);
		break;
	case SHARED_GEM_VLAN_MAP:
		memcpy((gem_vlan_map_t *)shared_data,_rdkb_omci_cfg_data->gemVlanMap,sizeof(gem_vlan_map_t) * RDKB_MAX_GEM_VLAN_MAP);
		break;
	default:
		ret = OMCI_LIB_FAIL;
		break;
	}
	pthread_rwlock_unlock(&_rdkb_omci_cfg_data->rwlock);			
	if(OMCI_LIB_SUCCESS != ret){
		RETURN_FAIL_MSG("Invalid shared information ERROR of get!\n");
	}else{
		RETURN_SUCCESS;
	}
}

static int set_rdkb_omci_cfg_data(rdkb_shared_cmd_t shared_cmd, void * shared_data)
{
	FUNC_TRACE_ENTER;
	int ret = OMCI_LIB_SUCCESS;

	if(NULL == shared_data){
		RETURN_FAIL_MSG("INPUT shared_data IS NULL\n");
	}

	if((NULL == _rdkb_omci_cfg_data ) && (OMCI_LIB_SUCCESS != init_rdkb_omci_cfg_data())){
        RETURN_FAIL_MSG("INIT RDKB Shared Data ERROR!\n");
    }

	pthread_rwlock_wrlock(&_rdkb_omci_cfg_data->rwlock);
	switch(shared_cmd){
	case SHARED_VOLTAGE_MIN_VOL:
		_rdkb_omci_cfg_data->voltageMinVol = atoi((char*)shared_data);
		break;
	case SHARED_VOLTAGE_MAX_VOL:
		_rdkb_omci_cfg_data->voltageMaxVol = atoi((char*)shared_data);
		break;
	case SHARED_BIAS_HIGH_BIAS:
		_rdkb_omci_cfg_data->biasHighBias = atoi((char*)shared_data);
		break;
		case SHARED_VEIP_COUNT:
			_rdkb_omci_cfg_data->veipEntryCount = *(int *)shared_data;
			break;
		case SHARED_TR69_COUNT:
			_rdkb_omci_cfg_data->tr69EntryCount = *(int *)shared_data;
			break;
		case SHARED_VEIP_LIST:
			memcpy(_rdkb_omci_cfg_data->veipList,(omci_rdkb_veip_t *)shared_data,sizeof(_rdkb_omci_cfg_data->veipList));
			break;
		case SHARED_TR69_LIST:
			memcpy(_rdkb_omci_cfg_data->tr69List,(omci_rdkb_tr69_t *)shared_data,sizeof(_rdkb_omci_cfg_data->tr69List));
			break;
		case SHARED_GEM_VLAN_MAP:
			memcpy(_rdkb_omci_cfg_data->gemVlanMap,(gem_vlan_map_t *)shared_data,sizeof(_rdkb_omci_cfg_data->gemVlanMap));
			break;
		case SHARED_OMCI_RESET:
			reset_gem_vlan_map();
			break;
		default:
			ret = OMCI_LIB_FAIL;
			break;
	}
	pthread_rwlock_unlock(&_rdkb_omci_cfg_data->rwlock);			
	if(OMCI_LIB_SUCCESS != ret){
		RETURN_FAIL_MSG("Invalid shared information ERROR o set!\n");
	}else{
		RETURN_SUCCESS;
	}
}


static int deinit_rdkb_omci_cfg_data(void)
{
    int shmid = -1;
    
    FUNC_TRACE_ENTER; 

    shmid = shmget((key_t)IPCKEY_RDKB, sizeof(omci_cfg_data_t), 0666 );
    if(-1 == shmid){
        RETURN_FAIL_MSG("GET RDKB SHAREMEM ID FAIL!\n");
    }

    pthread_rwlock_destroy(&_rdkb_omci_cfg_data->rwlock);
    
    if(-1 == shmdt(_rdkb_omci_cfg_data)){
        RETURN_FAIL_MSG("DETACH RDKB SHARE MEMORY ERROR!\n");
    }

    if(-1 == shmctl(shmid, IPC_RMID, 0)){
        RETURN_FAIL_MSG("DELETE RDKB SHARE MEMORY ERROR!\n");
    }
    
    RETURN_SUCCESS;
}

static int config_onu_shared_mem_default_data(void)
{
	unsigned char default_val[PRESHARED_KEY_LEN]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00};
	char default_ver[OMCI_VERSION_LENS]="RP0201";
	char default_vendor_id[OMCI_VENDOR_ID_LENS]="MTKG";
	char default_equipmentId[OMCI_EQUIPMENTID_LENS]="KE2.119.241R2B";	
	char default_sn[OMCI_SN_MEM_LENS]="MTKG00000001";
	char default_password[OMCI_PASSWD_LENS]="00000001";	
	int default_port_id[DEFAULT_MAX_PORTS]={48,248,47,47,47,47,32,32,49};
	uint8_t default_iphostMac[OMCI_IPHOST_MAC_LENS]={0x00,0xAA,0xBB,0x01,0x23,0x45};

	FUNC_TRACE_ENTER;

	if (NULL == _omci_cfg_data){
		RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	}		
	
	memcpy(_omci_cfg_data->enhancedPsk,default_val,sizeof(default_val));
	memcpy(_omci_cfg_data->version,default_ver,sizeof(default_ver));
	memcpy(_omci_cfg_data->vendorId,default_vendor_id,sizeof(default_vendor_id));
	memcpy(_omci_cfg_data->equipmentId,default_equipmentId,sizeof(default_equipmentId));
	memcpy(_omci_cfg_data->sn,default_sn,sizeof(default_sn));
	memcpy(_omci_cfg_data->password,default_password,sizeof(default_password));
	memcpy(_omci_cfg_data->iphostMac,default_iphostMac,sizeof(default_iphostMac));
	
	
	_omci_cfg_data->ponTrapThread = PON_TRAP_THREAD_START;
	_omci_cfg_data->rxPowerLowerThreshold = 0xff;
	_omci_cfg_data->rxPowerUpperThreshold = 0xff;
	_omci_cfg_data->txPowerLowerThreshold = 0x81;
	_omci_cfg_data->txPowerUpperThreshold = 0x81;
	_omci_cfg_data->linkMode = OMCI_LINK_MODE_GPON;
	_omci_cfg_data->usQMode = USQ_MODE_8Q;
	_omci_cfg_data->vendorProCode = 340;
	_omci_cfg_data->omccVersion = 0xA0;
	_omci_cfg_data->tmOption = 2;
	_omci_cfg_data->onuSurvivalTime = 10;
	_omci_cfg_data->extendedTcLayer = 3;
	_omci_cfg_data->securityCap = 0x01;
	_omci_cfg_data->totalTSNum = 16;
	_omci_cfg_data->totalPQNum = 160;
	_omci_cfg_data->totalGEMPortNum = 256;
	_omci_cfg_data->connectivityCap = 0x7F;
	_omci_cfg_data->qosConfFlex = 0x18;
	
	_omci_cfg_data->srIndication = 1;
	_omci_cfg_data->totalTcontNum = 16;
	_omci_cfg_data->gemBlockLength = 48;
	_omci_cfg_data->onuResponseTime = 35000;
	
	_omci_cfg_data->eventMonitorMask = 0xFFFFFFFF;
	
	_omci_cfg_data->maxPorts = DEFAULT_MAX_PORTS;
	memcpy(_omci_cfg_data->portId,default_port_id,(sizeof(int)*DEFAULT_MAX_PORTS));

	_omci_cfg_data->onuType = HGU;
	_omci_cfg_data->iphostNum = 2;

    _omci_cfg_data->onuSlot.uniGE= BASET101001000_SLOT;
	_omci_cfg_data->onuSlot.uniFE = BASET10100_SLOT;
	_omci_cfg_data->onuSlot.veip = VEIP_SLOT;
	_omci_cfg_data->onuSlot.pots = POTS_SLOT;
	_omci_cfg_data->onuSlot.videoUni = VIDEO_UNI_SLOT;
	_omci_cfg_data->onuSlot.videoAni = VIDEO_ANI_SLOT;
	_omci_cfg_data->onuSlot.gpon = GPON_SLOT;
	_omci_cfg_data->onuSlot.uni10GE = ETHER_10G_SLOT;
	_omci_cfg_data->onuSlot.uni2500E = ETHER_2500_SLOT;

	_omci_cfg_data->fileTransCtrl.protocol = 2;
	_omci_cfg_data->fileTransCtrl.fileType = 0;
	_omci_cfg_data->fileTransCtrl.fileInstance = 0;
	memset(&_omci_cfg_data->pptpVideoAni, 0, sizeof(pptp_video_ani_t));

	RETURN_SUCCESS;
}
/******************************************************************************
 Descriptor:    It's used to initialize a block of shared memory to store onu
                shared data. The shared memory address is stored in 
                _omci_cfg_data.
 Input Args:    NONE.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int init_omci_cfg_data(void)
{
    int shmid = -1;
    pthread_rwlockattr_t rwlattr;
    
    FUNC_TRACE_ENTER;
    
    if (NULL != _omci_cfg_data){
        RETURN_SUCCESS;
    }

    shmid = shmget((key_t)IPCKEY_ONU, sizeof(omci_cfg_data_t) , 0666);
    if(-1 == shmid){
        LIB_GPON_DEBUG("SHARE MEMORY NOT CREATE!\n");
        shmid = shmget((key_t)IPCKEY_ONU, sizeof(omci_cfg_data_t) , 0666|IPC_CREAT);
        if(-1 == shmid){
            RETURN_FAIL_MSG("CREATE SHARE MEMORY FAILED\n");
        }
	    _omci_cfg_data = (omci_cfg_data_t*)shmat(shmid, (void *)0, 0);
	    if (NULL == _omci_cfg_data){
	        RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	    }		
		memset(_omci_cfg_data, 0, sizeof(omci_cfg_data_t));

		config_onu_shared_mem_default_data();

	    /* Process Shared Read/Write lock */      
	    if(0 !=pthread_rwlockattr_init(&rwlattr)){
			goto FAIL;
	    }        
	    if(0 !=pthread_rwlockattr_setpshared(&rwlattr, PTHREAD_PROCESS_SHARED)){
			goto FAIL;
	    }    
	    if(0 !=pthread_rwlock_init(&_omci_cfg_data->rwlock, &rwlattr)){
			goto FAIL;
    	}  
	}else {
	    _omci_cfg_data = (omci_cfg_data_t*)shmat(shmid, (void *)0, 0);

		if (NULL == _omci_cfg_data){
	        RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	    }
    }    
	pthread_rwlockattr_destroy(&rwlattr);
    RETURN_SUCCESS;
	
FAIL:
	pthread_rwlockattr_destroy(&rwlattr);
	RETURN_FAIL;
}



/******************************************************************************
 Descriptor:    get shared_data from _omci_cfg_data
 Input Args:    shared_cmd 
 Output Args:   shared_data
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int get_omci_cfg_data(onu_shared_cmd_t shared_cmd, void *shared_data)
{
    FUNC_TRACE_ENTER;
	int ret = OMCI_LIB_SUCCESS;
   
    if(NULL == shared_data){
        RETURN_FAIL_MSG("INPUT shared_data IS NULL\n");
    }
    
    if((NULL == _omci_cfg_data ) && (OMCI_LIB_SUCCESS != init_omci_cfg_data())){
        RETURN_FAIL_MSG("INIT ONU Shared Data ERROR!\n");
    }
	pthread_rwlock_rdlock(&_omci_cfg_data->rwlock);
	switch(shared_cmd){
		case SHARED_RXPOWER_LOWER_THRESH:
			*(int *)shared_data = _omci_cfg_data->rxPowerLowerThreshold;
			break;
		case SHARED_RXPOWER_UPPER_THRESH:
			*(int *)shared_data = _omci_cfg_data->rxPowerUpperThreshold;
			break;
		case SHARED_TXPOWER_LOWER_THRESH:
			*(int *)shared_data = _omci_cfg_data->txPowerLowerThreshold;
			break;
		case SHARED_TXPOWER_UPPER_THRESH:
			*(int *)shared_data = _omci_cfg_data->txPowerUpperThreshold;
			break;
		case SHARED_ENHANCED_PSK:
			memcpy((unsigned char *)shared_data ,_omci_cfg_data->enhancedPsk,sizeof(_omci_cfg_data->enhancedPsk));
			break;
		case SHARED_ONU_VER:
			memcpy((char *)shared_data , _omci_cfg_data->version,sizeof(_omci_cfg_data->version));
			break;
		case SHARED_VENDOR_ID:
			memcpy((char *)shared_data ,_omci_cfg_data->vendorId,sizeof(_omci_cfg_data->vendorId));
			break;
		case SHARED_EQUIPMENT_ID:
			memcpy((char *)shared_data ,_omci_cfg_data->equipmentId,sizeof(_omci_cfg_data->equipmentId));
			break;
		case SHARED_SN:
			memcpy((unsigned char *)shared_data ,_omci_cfg_data->sn,sizeof(_omci_cfg_data->sn));
			break;
		case SHARED_PASSWORD:
			memcpy((char *)shared_data ,_omci_cfg_data->password,OMCI_PASSWD_LENS);
			break;
		case SHARED_REGID:			
			memcpy((char *)shared_data ,_omci_cfg_data->password,OMCI_REG_ID_LENS);
			break;
		case SHARED_LINK_MODE:
			*((onu_link_mode_t *)shared_data) = _omci_cfg_data->linkMode;
			break;
		case SHARED_USQ_MODE:
			if(_omci_cfg_data->usQMode == USQ_MODE_4Q || _omci_cfg_data->usQMode == USQ_MODE_8Q)
				*((char *)shared_data) = _omci_cfg_data->usQMode;
			break;
		case SHARED_VENDOR_PRO_CODE:
			*((unsigned short *)shared_data) = _omci_cfg_data->vendorProCode;
			break;
		case SHARED_OMCC_VERSION:
			*((unsigned char *)shared_data) = _omci_cfg_data->omccVersion;
			break;
		case SHARED_TM_OPTION:
			*((unsigned char *)shared_data) = _omci_cfg_data->tmOption;
			break;
		case SHARED_SURVIVAL_TIME:
			*((unsigned char *)shared_data) = _omci_cfg_data->onuSurvivalTime;
			break;
		case SHARED_EXT_TCLAYER:
			*((unsigned short *)shared_data) = _omci_cfg_data->extendedTcLayer;
			break;
		case SHARED_SECURITY_CAP:
			*((unsigned char *)shared_data) = _omci_cfg_data->securityCap;
			break;
		case SHARED_TS_NUM:
			*((unsigned char *)shared_data) = _omci_cfg_data->totalTSNum;
			break;
		case SHARED_PQ_NUM:
			*((unsigned short *)shared_data) = _omci_cfg_data->totalPQNum;
			break;
		case SHARED_GEM_NUM:
			*((unsigned short *)shared_data) = _omci_cfg_data->totalGEMPortNum;
			break;
		case SHARED_SYS_UP_TIME:
			*((unsigned int *)shared_data) = _omci_cfg_data->sysUpTime;
			break;
		case SHARED_CONNET_CAP:
			*((unsigned short *)shared_data) = _omci_cfg_data->connectivityCap;
			break;
		case SHARED_QOS_CONF_FLEX:
			*((unsigned short *)shared_data) = _omci_cfg_data->qosConfFlex;
			break;
		case SHARED_SR_INDICT:
			*((unsigned char *)shared_data) = _omci_cfg_data->srIndication;
			break;
		case SHARED_TCONT_NUM:
			*((unsigned short *)shared_data) = _omci_cfg_data->totalTcontNum;
			break;
		case SHARED_GEM_BLOCK_LEN:
			*((unsigned short *)shared_data) = _omci_cfg_data->gemBlockLength;
			break;
		case SHARED_ONU_RES_TIME:
			*((unsigned short *)shared_data) = _omci_cfg_data->onuResponseTime;
			break;
		case SHARED_MAX_PORTS:
			*((char *)shared_data) = _omci_cfg_data->maxPorts;
			break;
		case SHARED_PORT_LIST:
			memcpy((int *)shared_data ,_omci_cfg_data->portId,(sizeof(int)*_omci_cfg_data->maxPorts));
			break;
		case SHARED_ONU_TYPE:
			*((unsigned char *)shared_data) = _omci_cfg_data->onuType;
			break;
		case SHARED_EVENT_MONITOR_MASK:
			*((unsigned int *)shared_data) = _omci_cfg_data->eventMonitorMask;
			break;
		case SHARED_TIME_STATUS_MSG:
			memcpy((time_status_msg_t *)shared_data,&_omci_cfg_data->timeStatusMsg ,sizeof(time_status_msg_t));
			break;
		case SHARED_ONU_SLOT:
		    memcpy((omciOnuSlot_t *)shared_data,&_omci_cfg_data->onuSlot,sizeof(omciOnuSlot_t));
			break;
		case SHARED_ALL_DATA:
			memcpy((omci_cfg_data_t *)shared_data,_omci_cfg_data,sizeof(omci_cfg_data_t));
			break;
		case SHARED_IPHOST_MAC:
			memcpy((unsigned char *)shared_data ,_omci_cfg_data->iphostMac,sizeof(_omci_cfg_data->iphostMac));
			break;
		case SHARED_IPHOST_NUM:
		    *((unsigned char *)shared_data) = _omci_cfg_data->iphostNum ;
		    break;
		case SHARED_FILE_TRANSFER_CTRL:
            memcpy((file_transfer_ctrl_t *)shared_data,&_omci_cfg_data->fileTransCtrl,sizeof(file_transfer_ctrl_t));
		    break;
		case SHARED_VIDEO_ANI_CFG:
		    memcpy((pptp_video_ani_t *)shared_data,&_omci_cfg_data->pptpVideoAni,sizeof(pptp_video_ani_t));
			break;
		case SHARED_AUTH_METH:
			memcpy((auth_security_meth_t *)shared_data,&_omci_cfg_data->authSecurityMeth,sizeof(auth_security_meth_t));
			break;
		case SHARED_PON_TRAP_THREAD:
			*(int *)shared_data = _omci_cfg_data->ponTrapThread;
			break;
		default:
			ret = OMCI_LIB_FAIL;
			break;
		}
	pthread_rwlock_unlock(&_omci_cfg_data->rwlock);			
	if(OMCI_LIB_SUCCESS != ret){
		RETURN_FAIL_MSG("Invalid shared information ERROR!\n");
	}else{
		RETURN_SUCCESS;
	}
    
}
/******************************************************************************
 Descriptor:    set shared_data to _omci_cfg_data
 Input Args:    shared_cmd   shared_data
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int set_omci_cfg_data(onu_shared_cmd_t shared_cmd, void *shared_data)
{
    FUNC_TRACE_ENTER;

    if(NULL == shared_data){
        RETURN_FAIL_MSG("INPUT shared_data IS NULL\n");
    }
    
    if((NULL == _omci_cfg_data ) && (OMCI_LIB_SUCCESS != init_omci_cfg_data() ) ){
        RETURN_FAIL_MSG("INIT ONU Shared Data ERROR!\n");
    }

	pthread_rwlock_wrlock(&_omci_cfg_data->rwlock);
	switch(shared_cmd){
		case SHARED_RXPOWER_LOWER_THRESH:
			{
				_omci_cfg_data->rxPowerLowerThreshold = *(int *)shared_data;
			}
			break;
		case SHARED_RXPOWER_UPPER_THRESH:
			{
				_omci_cfg_data->rxPowerUpperThreshold = *(int *)shared_data;
			}
			break;
		case SHARED_TXPOWER_LOWER_THRESH:
			{
				_omci_cfg_data->txPowerLowerThreshold = *(int *)shared_data;
			}
			break;
		case SHARED_TXPOWER_UPPER_THRESH:
			{
				_omci_cfg_data->txPowerUpperThreshold = *(int *)shared_data;
			}
			break;
		case SHARED_ENHANCED_PSK:
			memcpy(_omci_cfg_data->enhancedPsk,(unsigned char *)shared_data,sizeof(_omci_cfg_data->enhancedPsk));
			break;
		case SHARED_ONU_VER:
			memcpy(_omci_cfg_data->version,(char *)shared_data,sizeof(_omci_cfg_data->version));
			break;
		case SHARED_VENDOR_ID:
			memcpy(_omci_cfg_data->vendorId,(char *)shared_data,sizeof(_omci_cfg_data->vendorId));
			break;
		case SHARED_EQUIPMENT_ID:
			memcpy(_omci_cfg_data->equipmentId,(char *)shared_data,sizeof(_omci_cfg_data->equipmentId));
			break;
		case SHARED_SN:
			memcpy(_omci_cfg_data->sn,(char *)shared_data,sizeof(_omci_cfg_data->sn));
			break;
		case SHARED_PASSWORD:
		case SHARED_REGID:			
			memcpy(_omci_cfg_data->password,(char *)shared_data,sizeof(_omci_cfg_data->password));
			break;
		case SHARED_LINK_MODE:
			_omci_cfg_data->linkMode= *((char *)shared_data);
			break;
		case SHARED_USQ_MODE:
			_omci_cfg_data->usQMode= *((char *)shared_data);
			break;
		case SHARED_VENDOR_PRO_CODE:
			_omci_cfg_data->vendorProCode= *((unsigned short *)shared_data);
			break;
		case SHARED_OMCC_VERSION:
			_omci_cfg_data->omccVersion= *((unsigned char *)shared_data);
			break;
		case SHARED_TM_OPTION:
			_omci_cfg_data->tmOption= *((unsigned char *)shared_data);
			break;
		case SHARED_SURVIVAL_TIME:
			_omci_cfg_data->onuSurvivalTime = *((unsigned char *)shared_data);
			break;
		case SHARED_EXT_TCLAYER:
			_omci_cfg_data->extendedTcLayer = *((unsigned char *)shared_data);
			break;
		case SHARED_SECURITY_CAP:
			_omci_cfg_data->securityCap = *((unsigned char *)shared_data);
			break;
		case SHARED_TS_NUM:
			_omci_cfg_data->totalTSNum= *((unsigned char *)shared_data);
			break;
		case SHARED_PQ_NUM:
			_omci_cfg_data->totalPQNum= *((unsigned short *)shared_data);
			break;
		case SHARED_GEM_NUM:
			_omci_cfg_data->totalGEMPortNum= *((unsigned short *)shared_data);
			break;
		case SHARED_SYS_UP_TIME:
			_omci_cfg_data->sysUpTime= *((unsigned int *)shared_data);
			break;
		case SHARED_CONNET_CAP:
			_omci_cfg_data->connectivityCap= *((unsigned short *)shared_data);
			break;
		case SHARED_QOS_CONF_FLEX:
			_omci_cfg_data->qosConfFlex= *((unsigned short *)shared_data);
			break;
		case SHARED_SR_INDICT:
			_omci_cfg_data->srIndication= *((unsigned char *)shared_data);
			break;
		case SHARED_TCONT_NUM:
			_omci_cfg_data->totalTcontNum= *((unsigned short *)shared_data);
			break;
		case SHARED_GEM_BLOCK_LEN:
			_omci_cfg_data->gemBlockLength= *((unsigned short *)shared_data);
			break;
		case SHARED_ONU_RES_TIME:
			_omci_cfg_data->onuResponseTime= *((unsigned short *)shared_data);
			break;
		case SHARED_MAX_PORTS:
			_omci_cfg_data->maxPorts = *((char *)shared_data);
			break;
		case SHARED_PORT_LIST:
			memcpy(_omci_cfg_data->portId,(int *)shared_data,(sizeof(int)*_omci_cfg_data->maxPorts));
			break;
		case SHARED_ONU_TYPE:
			_omci_cfg_data->onuType= *((unsigned char *)shared_data);
			break;
		case SHARED_EVENT_MONITOR_MASK:
			 _omci_cfg_data->eventMonitorMask = *((unsigned int *)shared_data);
			 break;
		 case SHARED_TIME_STATUS_MSG:
			 memcpy(&_omci_cfg_data->timeStatusMsg,(time_status_msg_t *)shared_data,sizeof(time_status_msg_t));
			 break;
		case SHARED_ONU_SLOT:
			memcpy(&_omci_cfg_data->onuSlot,(omciOnuSlot_t *)shared_data,sizeof(omciOnuSlot_t));
			break;
		case SHARED_ALL_DATA:
			memcpy(_omci_cfg_data,(omci_cfg_data_t *)shared_data,sizeof(omci_cfg_data_t));
			break;
		case SHARED_IPHOST_MAC:
			memcpy(_omci_cfg_data->iphostMac,(unsigned char *)shared_data ,sizeof(_omci_cfg_data->iphostMac));
			break;
		case SHARED_IPHOST_NUM:
		    _omci_cfg_data->iphostNum = *((unsigned char *)shared_data);
		    break;
		case SHARED_FILE_TRANSFER_CTRL:
            memcpy(&_omci_cfg_data->fileTransCtrl,(file_transfer_ctrl_t *)shared_data,sizeof(file_transfer_ctrl_t));
		    break;
		case SHARED_VIDEO_ANI_CFG:
		    memcpy(&_omci_cfg_data->pptpVideoAni,(pptp_video_ani_t *)shared_data,sizeof(pptp_video_ani_t));
			break;
		case SHARED_AUTH_METH:
			memcpy(&_omci_cfg_data->authSecurityMeth,(auth_security_meth_t *)shared_data,sizeof(auth_security_meth_t));
			break;
		case SHARED_PON_TRAP_THREAD:
			_omci_cfg_data->ponTrapThread = *((int *)shared_data);
			break;
		default:
			LIB_GPON_ERROR("Invalid shared information ERROR!\n");
			break;
	}
	pthread_rwlock_unlock(&_omci_cfg_data->rwlock);			
	
	RETURN_SUCCESS;
}

int omci_lib_uci_get(char *option, char *value, unsigned int size)
{
	FILE *fp = NULL;
	char cmd[256] = {0};
	
	sprintf(cmd, "uci -q get %s > /tmp/tmp_uci_value", option);
	system(cmd);
	fp = fopen("/tmp/tmp_uci_value", "r");
	if(fp == NULL)
		return -1;
	
    fgets(value, size, fp);
	
    if(value[strlen(value)-1] == '\n')
        value[strlen(value)-1] = '\0';
	
    fclose(fp);
	unlink("/tmp/tmp_uci_value");
	
	return 0;
}

/******************************************************************************
 Descriptor:    It's used to detach a block of shared memory to store onu
                shared data. The shared memory address is stored in 
                _omci_cfg_data.and delete this share memory.
 Input Args:    NONE.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int deinit_omci_cfg_data(void)
{
    int shmid = -1;
    
    FUNC_TRACE_ENTER; 

    shmid = shmget((key_t)IPCKEY_ONU, sizeof(omci_cfg_data_t), 0666 );
    if(-1 == shmid){
        RETURN_FAIL_MSG("GET SHAREMEM ID FAIL!\n");
    }

    pthread_rwlock_destroy(&_omci_cfg_data->rwlock);
    
    if(-1 == shmdt(_omci_cfg_data)){
        RETURN_FAIL_MSG("DETACH SHARE MEMORY ERROR!\n");
    }

    if(-1 == shmctl(shmid, IPC_RMID, 0)){
        RETURN_FAIL_MSG("DELETE SHARE MEMORY ERROR!\n");
    }
    
    RETURN_SUCCESS;
}

static int config_omci_internal_mem_default_data(void)
{
	FUNC_TRACE_ENTER;
    char default_operatorID_cap[OMCI_OPERATOR_ID_LENS]="CTC";
    char default_operatorID_auth[OMCI_OPERATOR_ID_LENS]="CTC";
    char default_LOID[OMCI_LOID_LENS]="mtk1111";
    char default_LOID_Password[OMCI_LOID_PASSWORD_LENS]="1111";


	if (NULL == _omci_internal_data){
		RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	}		
	
	_omci_internal_data->omci_fsm_cond = 0;
	memcpy(_omci_internal_data->operatorID_cap,default_operatorID_cap,sizeof(default_operatorID_cap));
    memcpy(_omci_internal_data->Loid,default_LOID,sizeof(default_LOID));
    memcpy(_omci_internal_data->LOID_Password,default_LOID_Password,sizeof(default_LOID_Password));
    memcpy(_omci_internal_data->operatorID_auth,default_operatorID_auth,sizeof(default_operatorID_auth));
    _omci_internal_data->SpecVersion = 0;
    _omci_internal_data->ONU_PowerCtr = 0;
    _omci_internal_data->AuthStatus = 0;
	_omci_internal_data->VoIPbyTR069 = 0;/*If TR69, then set 1!*/
    _omci_internal_data->vlanFilterIPHostEn = 0;
	_omci_internal_data->conReqPort = 7547;
	_omci_internal_data->DebugLevel = 0; /*OMCI_DEBUG_LEVEL_NO_MSG*/
	_omci_internal_data->LanDebug = 0; 
	memset(&_omci_internal_data->CompileOption,0,sizeof(CompileOp_t));
	_omci_internal_data->romfile_load_flag = 0;
	memset(&_omci_internal_data->omciAttrDefVal,0,sizeof(omciAttrDefVal_t));
	_omci_internal_data->selfDefVD = 0;
	_omci_internal_data->mibDataSyncInitVal = 0;
	_omci_internal_data->AESKeyMode = 4;

	RETURN_SUCCESS;
}

/******************************************************************************
 Descriptor:    It's used to initialize a block of shared memory to store onu
                shared data. The shared memory address is stored in 
                _omci_internal_data.
 Input Args:    NONE.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int init_omci_internal_data(void)
{
    int shmid = -1;
    pthread_rwlockattr_t rwlattr;
    
    FUNC_TRACE_ENTER;
    
    if (NULL != _omci_internal_data){
        RETURN_SUCCESS;
    }

    shmid = shmget((key_t)IPCKEY_OMCI_INTERNAL, sizeof(omci_internal_shared_data_t) , 0666);
    if(-1 == shmid){
        LIB_GPON_DEBUG("SHARE MEMORY NOT CREATE!\n");
        shmid = shmget((key_t)IPCKEY_OMCI_INTERNAL, sizeof(omci_internal_shared_data_t) , 0666|IPC_CREAT);
        if(-1 == shmid){
            RETURN_FAIL_MSG("CREATE SHARE MEMORY FAILED\n");
        }
	    _omci_internal_data = (omci_internal_shared_data_t*)shmat(shmid, (void *)0, 0);
	    if (NULL == _omci_internal_data){
	        RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	    }		
		memset(_omci_internal_data, 0, sizeof(omci_internal_shared_data_t));

		config_omci_internal_mem_default_data();

	    /* Process Shared Read/Write lock */      
	    if(0 !=pthread_rwlockattr_init(&rwlattr)){
			goto FAIL;
	    }        
	    if(0 !=pthread_rwlockattr_setpshared(&rwlattr, PTHREAD_PROCESS_SHARED)){
			goto FAIL;
	    }    
	    if(0 !=pthread_rwlock_init(&_omci_internal_data->rwlock, &rwlattr)){
			goto FAIL;
    	}  
	}else {
	    _omci_internal_data = (omci_internal_shared_data_t*)shmat(shmid, (void *)0, 0);

		if (NULL == _omci_internal_data){
	        RETURN_FAIL_MSG("ATTACH SHARE MEMORY ERROR!\n");
	    }
    }    
	pthread_rwlockattr_destroy(&rwlattr);
    RETURN_SUCCESS;
	
FAIL:
	pthread_rwlockattr_destroy(&rwlattr);
	RETURN_FAIL;
}

/******************************************************************************
 Descriptor:    get shared_data from _omci_internal_data
 Input Args:    shared_cmd 
 Output Args:   shared_data
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int get_omci_internal_data(onu_internal_cmd_t shared_cmd, void *shared_data)
{
    FUNC_TRACE_ENTER;
	int ret = OMCI_LIB_SUCCESS;
   
    if(NULL == shared_data){
        RETURN_FAIL_MSG("INPUT shared_data IS NULL\n");
    }
    
    if((NULL == _omci_internal_data ) && (OMCI_LIB_SUCCESS != init_omci_internal_data())){
        RETURN_FAIL_MSG("INIT ONU Shared Data ERROR!\n");
    }
	pthread_rwlock_rdlock(&_omci_internal_data->rwlock);
	switch(shared_cmd){
		case SHARED_FSM_COND:
			((omci_fsm_cond_data_t *)shared_data)->condition = _omci_internal_data->omci_fsm_cond;
			break;
        case SHARED_OPERATOR_ID_CAP:
			memcpy((char *)shared_data ,_omci_internal_data->operatorID_cap,sizeof(_omci_internal_data->operatorID_cap));
			break;
		case SHARED_OPERATOR_ID_AUTH:
			memcpy((char *)shared_data ,_omci_internal_data->operatorID_auth, sizeof(_omci_internal_data->operatorID_auth));
			break;
	    case SHARED_LOID:
			memcpy((char *)shared_data ,_omci_internal_data->Loid,sizeof(_omci_internal_data->Loid));
			break;
		case SHARED_LOID_PASSWORD:
			memcpy((char *)shared_data ,_omci_internal_data->LOID_Password,sizeof(_omci_internal_data->LOID_Password));
			break;
		case SHARED_AUTH_STATUS:
			*((unsigned char *)shared_data) = _omci_internal_data->AuthStatus;
			break;
		case SHARED_SPEC_VER:
			*((unsigned char *)shared_data) = _omci_internal_data->SpecVersion;
			break;
		case SHARED_ONU_POWER_CTRL:
			*((unsigned char *)shared_data) = _omci_internal_data->ONU_PowerCtr;
			break;
		case SHARED_ROMFILE_LOAD_FLAG:
			*((unsigned char *)shared_data) = _omci_internal_data->romfile_load_flag;
			break;
		case SHARED_EMERGENCY_STATE:
			*((unsigned char *)shared_data) = _omci_internal_data->emergencyState;
			break;
		case SHARED_OLT_TYPE:
		    memcpy((char *)shared_data ,_omci_internal_data->oltType,sizeof(_omci_internal_data->oltType));
		    break;
		case SHARED_VIOP_BY_TR069:
			*((char *)shared_data) = _omci_internal_data->VoIPbyTR069;
			break;
		case SHARED_VIOP_SEP_EN:
			*((char *)shared_data) = _omci_internal_data->VoIPSepEn;
			break;
		case SHARED_CON_REQ_PORT:
			*((unsigned short *)shared_data) = _omci_internal_data->conReqPort;
			break;
		case SHARED_DBG_LEVEL:
			*((unsigned char *)shared_data) = _omci_internal_data->DebugLevel;
			break;
		case SHARED_LAN_DBG:
			*((unsigned char *)shared_data) = _omci_internal_data->LanDebug;
			break;
		case SHARED_COMPILE_OPTION:
			memcpy((CompileOp_t *)shared_data,&_omci_internal_data->CompileOption,sizeof(CompileOp_t));
			break;
		case SHARED_OMCI_ATTR_DEF_VAL:
			memcpy((omciAttrDefVal_t *)shared_data,&_omci_internal_data->omciAttrDefVal,sizeof(omciAttrDefVal_t));
			break;
		case SHARED_SELF_DEF_VD:
			*((unsigned char *)shared_data) = _omci_internal_data->selfDefVD;
			break;
		case SHARED_STRICT_PPTP_ETHUNI_SLOT:
			*((unsigned char *)shared_data) = _omci_internal_data->strictPPTPEthUniSlot;
			break;
		case SHARED_MIB_DATA_SYNC_INIT:
		    *((unsigned char *)shared_data) = _omci_internal_data->mibDataSyncInitVal;
		    break;
		case SHARED_LIB_DBG_LEVEL:
			*((uint8_t *)shared_data) = _omci_internal_data->libDbgLevel;
			break;
        case SHARED_VLAN_FILTER_IPHOST_EN:
            *((unsigned char *)shared_data) = _omci_internal_data->vlanFilterIPHostEn;
            break;
        case SHARED_UP_AES_MODE:
			*((unsigned char *)shared_data) = _omci_internal_data->AESKeyMode;
			break;
		default:
			ret = OMCI_LIB_FAIL;
			break;
		}
	pthread_rwlock_unlock(&_omci_internal_data->rwlock);			
	if(OMCI_LIB_SUCCESS != ret){
		RETURN_FAIL_MSG("Invalid shared information ERROR!\n");
	}else{
		RETURN_SUCCESS;
	}
    
}

/******************************************************************************
 Descriptor:    set shared_data to _omci_internal_data
 Input Args:    shared_cmd   shared_data
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int set_omci_internal_data(onu_internal_cmd_t shared_cmd, void *shared_data)
{
    FUNC_TRACE_ENTER;

    if(NULL == shared_data){
        RETURN_FAIL_MSG("INPUT shared_data IS NULL\n");
    }
    
    if((NULL == _omci_internal_data ) && (OMCI_LIB_SUCCESS != init_omci_internal_data() ) ){
        RETURN_FAIL_MSG("INIT ONU Shared Data ERROR!\n");
    }

	pthread_rwlock_wrlock(&_omci_internal_data->rwlock);
	switch(shared_cmd){
		case SHARED_FSM_COND:
			_omci_internal_data->omci_fsm_cond &= ~((omci_fsm_cond_data_t *)shared_data)->condition_mask;
			_omci_internal_data->omci_fsm_cond |= (((omci_fsm_cond_data_t *)shared_data)->condition & ((omci_fsm_cond_data_t *)shared_data)->condition_mask);
			break;
	    case SHARED_OPERATOR_ID_CAP:
			memcpy(_omci_internal_data->operatorID_cap,(char *)shared_data,sizeof(_omci_internal_data->operatorID_cap));
			break;
		case SHARED_OPERATOR_ID_AUTH:
			memcpy(_omci_internal_data->operatorID_auth,(char *)shared_data,sizeof(_omci_internal_data->operatorID_auth));
			break;
		case SHARED_LOID:
			memcpy(_omci_internal_data->Loid,(char *)shared_data,sizeof(_omci_internal_data->Loid));
			break;
		case SHARED_LOID_PASSWORD:
			memcpy(_omci_internal_data->LOID_Password,(char *)shared_data,sizeof(_omci_internal_data->LOID_Password));
			break;
		case SHARED_AUTH_STATUS:
			_omci_internal_data->AuthStatus= *((unsigned char *)shared_data);
			break;
		case SHARED_SPEC_VER:
			_omci_internal_data->SpecVersion= *((unsigned char *)shared_data);
			break;
		case SHARED_ONU_POWER_CTRL:
			_omci_internal_data->ONU_PowerCtr= *((unsigned char *)shared_data);
			break;
		case SHARED_ROMFILE_LOAD_FLAG:
			_omci_internal_data->romfile_load_flag = *((unsigned char *)shared_data);
			break;
		case SHARED_EMERGENCY_STATE:
			_omci_internal_data->emergencyState = *((unsigned char *)shared_data);
			break;
		case SHARED_OLT_TYPE:
		    memcpy(_omci_internal_data->oltType,(char *)shared_data,sizeof(_omci_internal_data->oltType));
		    break;
		case SHARED_VIOP_BY_TR069:
			_omci_internal_data->VoIPbyTR069= *((char *)shared_data);
			break;
		case SHARED_VIOP_SEP_EN:
			_omci_internal_data->VoIPSepEn= *((char *)shared_data);
			break;
		case SHARED_CON_REQ_PORT:
			_omci_internal_data->conReqPort= *((unsigned short *)shared_data);
			break;
		case SHARED_DBG_LEVEL:
			_omci_internal_data->DebugLevel = *((unsigned char *)shared_data);
			break;
		case SHARED_LAN_DBG:
			_omci_internal_data->LanDebug = *((unsigned char *)shared_data);
			break;
		case SHARED_COMPILE_OPTION:
			memcpy(&_omci_internal_data->CompileOption,(CompileOp_t *)shared_data,sizeof(CompileOp_t));
			break;
		case SHARED_OMCI_ATTR_DEF_VAL:
			memcpy(&_omci_internal_data->omciAttrDefVal,(omciAttrDefVal_t *)shared_data,sizeof(omciAttrDefVal_t));
			break;
		case SHARED_SELF_DEF_VD:
			_omci_internal_data->selfDefVD = *((unsigned char *)shared_data) ;
			break;
		case SHARED_STRICT_PPTP_ETHUNI_SLOT:
			_omci_internal_data->strictPPTPEthUniSlot= *((unsigned char *)shared_data) ;
			//omciScreenPrintf("[%s][%d]: pOnuCap->strictPPTPEthUniSlot = %d\n",__FUNCTION__, __LINE__,_omci_internal_data->strictPPTPEthUniSlot);
			break;
		case SHARED_MIB_DATA_SYNC_INIT:
		    _omci_internal_data->mibDataSyncInitVal = *((unsigned char *)shared_data) ;
		    break;
        case SHARED_VLAN_FILTER_IPHOST_EN:
            _omci_internal_data->vlanFilterIPHostEn = *((unsigned char *)shared_data);
            break;
		case SHARED_LIB_DBG_LEVEL:
			_omci_internal_data->libDbgLevel = *((uint8_t *)shared_data);
			break;
        case SHARED_UP_AES_MODE:
            _omci_internal_data->AESKeyMode = *((unsigned char *)shared_data);
            break;
		default:
			LIB_GPON_ERROR("Invalid shared information ERROR!\n");
			break;
	}
	pthread_rwlock_unlock(&_omci_internal_data->rwlock);			
	
	RETURN_SUCCESS;
}


/******************************************************************************
 Descriptor:    It's used to detach a block of shared memory to store onu
                shared data. The shared memory address is stored in 
                _omci_internal_data.and delete this share memory.
 Input Args:    NONE.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
static int deinit_omci_internal_data(void)
{
    int shmid = -1;
    
    FUNC_TRACE_ENTER; 

    shmid = shmget((key_t)IPCKEY_ONU, sizeof(omci_cfg_data_t), 0666 );
    if(-1 == shmid){
        RETURN_FAIL_MSG("GET SHAREMEM ID FAIL!\n");
    }

    pthread_rwlock_destroy(&_omci_internal_data->rwlock);
    
    if(-1 == shmdt(_omci_internal_data)){
        RETURN_FAIL_MSG("DETACH SHARE MEMORY ERROR!\n");
    }

    if(-1 == shmctl(shmid, IPC_RMID, 0)){
        RETURN_FAIL_MSG("DELETE SHARE MEMORY ERROR!\n");
    }
    
    RETURN_SUCCESS;
}

/******************************************************************************
 Descriptor:    It's used to initialize gpon manager lib.
 Input Args:    NONE.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_init(void)
{
    if(OMCI_LIB_SUCCESS != init_omci_cfg_data()){
        RETURN_FAIL_MSG("init_onu_shared_data fail!\n");
    }

	if(OMCI_LIB_SUCCESS != init_rdkb_omci_cfg_data()){
        RETURN_FAIL_MSG("init_rdkb_shared_data fail!\n");
    }
    RETURN_SUCCESS;
}

/******************************************************************************
 Descriptor:    It's used to deinitialize gpon manager lib.
 Input Args:    NONE.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_deinit(void)
{
    FUNC_TRACE_ENTER;

    if(OMCI_LIB_SUCCESS != deinit_omci_cfg_data()){
        RETURN_FAIL_MSG("deinit_onu_shared_data fail!\n");
    }

    if(OMCI_LIB_SUCCESS != deinit_omci_internal_data()){
        RETURN_FAIL_MSG("deinit_omci_internal_data fail!\n");
    }

	if(OMCI_LIB_SUCCESS != deinit_rdkb_omci_cfg_data()){
        RETURN_FAIL_MSG("deinit_rdkb_omci_cfg_data fail!\n");
    }
	
    RETURN_SUCCESS;
}

void omci_lib_dbg_printf(uint8_t debugLevel, char *fmt,...)
{

	FILE *proc_file;
	char msg[256] = {0};
	va_list args;

	if(_omci_internal_data == NULL || debugLevel > _omci_internal_data->libDbgLevel )
		return;
	
	va_start(args, fmt);

	vsnprintf(msg, 256, fmt, args);	

    //proc_file = fopen("/proc/tc3162/dbg_msg", "w");
    proc_file = fopen("/tmp/omci_lib_debug", "a+");
	if (!proc_file) {
		printf("open /tmp/omci_lib_debug fail\n");
		va_end(args);
		return;
	}
	if(debugLevel == OMCI_LIB_DEBUG_LEVEL_ERROR){
		fprintf(proc_file, "%s", "**ERROR** ");
	}

	fprintf(proc_file, "%s", msg);
	fclose(proc_file);
	va_end(args);
}

int omci_lib_set_pon_trap_thread(int ponTrapThread)
{
	if(ponTrapThread != PON_TRAP_THREAD_START && ponTrapThread != PON_TRAP_THREAD_STOP){
		return -1;
	}
		
	return set_omci_cfg_data(SHARED_PON_TRAP_THREAD, &ponTrapThread);
}

int omci_lib_get_pon_trap_thread(int * ponTrapThread)
{
	if(NULL == ponTrapThread){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_PON_TRAP_THREAD, ponTrapThread);
}

int omci_lib_set_rxPower_lowerThreshold(int lowerThreshold)
{
	return set_omci_cfg_data(SHARED_RXPOWER_LOWER_THRESH, &lowerThreshold);
}

int omci_lib_set_rxPower_upperThreshold(int upperThreshold)
{
	return set_omci_cfg_data(SHARED_RXPOWER_UPPER_THRESH, &upperThreshold);
}

int omci_lib_set_txPower_lowerThreshold(int lowerThreshold)
{
	return set_omci_cfg_data(SHARED_TXPOWER_LOWER_THRESH, &lowerThreshold);
}

int omci_lib_set_txPower_upperThreshold(int upperThreshold)
{
	return set_omci_cfg_data(SHARED_TXPOWER_UPPER_THRESH, &upperThreshold);
}

int omci_lib_set_rdkb_voltage_minVol(char *minVol)
{
	if (NULL == minVol)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}

	return set_rdkb_omci_cfg_data(SHARED_VOLTAGE_MIN_VOL, minVol);
}

int omci_lib_set_rdkb_voltage_maxVol(char *maxVol)
{
	if (NULL == maxVol)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}

	return set_rdkb_omci_cfg_data(SHARED_VOLTAGE_MAX_VOL, maxVol);
}

int omci_lib_set_rdkb_bias_highBias(char *highBias)
{
	if (NULL == highBias)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}

	return set_rdkb_omci_cfg_data(SHARED_BIAS_HIGH_BIAS, highBias);
}

int omci_lib_set_rdkb_veip_adminState(uint16_t  meid, uint8_t * attrValue)
{
	int i = 0;
	int entryCount = 0;
	omci_rdkb_veip_t veipList[VEIP_INST_MAX_NUM];

	memset(veipList,0,sizeof(omci_rdkb_veip_t)*VEIP_INST_MAX_NUM);
	get_rdkb_omci_cfg_data(SHARED_VEIP_LIST,veipList);
	get_rdkb_omci_cfg_data(SHARED_VEIP_COUNT,&entryCount);
	for(i = 0 ; i < entryCount; i++){
		if(veipList[i].meId == meid)
			veipList[i].adminState = *attrValue;
	}
	return set_rdkb_omci_cfg_data(SHARED_VEIP_LIST, veipList);
}

int omci_lib_set_rdkb_veip_interdomain_name(uint16_t  meid, char * attrValue)
{
	int i = 0;
	int entryCount = 0;
	omci_rdkb_veip_t veipList[VEIP_INST_MAX_NUM];

	if(attrValue == NULL){
		return -1;
	}
	else if(strlen(attrValue) >= sizeof(veipList[0].interdomainName)){
		return -1;
	}

	memset(veipList,0,sizeof(omci_rdkb_veip_t)*VEIP_INST_MAX_NUM);
	get_rdkb_omci_cfg_data(SHARED_VEIP_LIST,veipList);
	get_rdkb_omci_cfg_data(SHARED_VEIP_COUNT,&entryCount);
	for(i = 0 ; i < entryCount; i++){
		if(veipList[i].meId == meid){
			memset(veipList[i].interdomainName,0,sizeof(veipList[0].interdomainName));
			memcpy(veipList[i].interdomainName,attrValue,strlen(attrValue));
			break;
		}
	}
	return set_rdkb_omci_cfg_data(SHARED_VEIP_LIST, veipList);
}

int omci_lib_set_rdkb_veip_list(omci_rdkb_veip_t * meInfo)
{
	if(NULL == meInfo){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return set_rdkb_omci_cfg_data(SHARED_VEIP_LIST, meInfo);
}

int omci_lib_set_rdkb_tr69_list(omci_rdkb_tr69_t * tr69InstList)
{
	if(NULL == tr69InstList){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return set_rdkb_omci_cfg_data(SHARED_TR69_LIST, tr69InstList);
}

int omci_lib_set_rdkb_tr69_entry_count(int * entryNumber)
{
	if(NULL == entryNumber){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return set_rdkb_omci_cfg_data(SHARED_TR69_COUNT, entryNumber);
}

int omci_lib_set_rdkb_veip_entry_count(int * entryNumber)
{
	if(NULL == entryNumber){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return set_rdkb_omci_cfg_data(SHARED_VEIP_COUNT, entryNumber);
}

int omci_lib_set_rdkb_tr69_url(uint16_t meid, char * buffer)
{	
	int i = 0;
	int entryCount = 0;
	omci_rdkb_tr69_t tr69List[TR69_INST_MAX_NUM];
	if(NULL == buffer){
		RETURN_FAIL_MSG("input param is null\n");
	}
	
	memset(tr69List,0,sizeof(omci_rdkb_tr69_t) * TR69_INST_MAX_NUM);
	get_rdkb_omci_cfg_data(SHARED_TR69_LIST,tr69List);
	get_rdkb_omci_cfg_data(SHARED_TR69_COUNT,&entryCount);
	for(i = 0; i < entryCount; i++){
		if(tr69List[i].meId == meid)
			strcpy(tr69List[i].acsNetworkAddress,buffer);
	}
	return set_rdkb_omci_cfg_data(SHARED_TR69_LIST, tr69List);
}

int  omci_lib_set_rdkb_tr69_associatedTag(uint16_t meid, uint16_t * asscociatedTag)
{	
	int i = 0;
	int entryCount = 0;
	omci_rdkb_tr69_t tr69List[TR69_INST_MAX_NUM];
	if(NULL == asscociatedTag){
		RETURN_FAIL_MSG("input param is null\n");
	}

	memset(tr69List,0,sizeof(omci_rdkb_tr69_t) * TR69_INST_MAX_NUM);
	get_rdkb_omci_cfg_data(SHARED_TR69_LIST,tr69List);
	get_rdkb_omci_cfg_data(SHARED_TR69_COUNT,&entryCount);
	for(i = 0; i < entryCount; i++){
		if(tr69List[i].meId == meid)
			memcpy(&tr69List[i].associatedTag,asscociatedTag,sizeof(uint16_t));
	}
	return set_rdkb_omci_cfg_data(SHARED_TR69_LIST, tr69List);
}

int omci_lib_set_rdkb_omci_reset(void)
{
	int reset_flag = 1;
	return set_rdkb_omci_cfg_data(SHARED_OMCI_RESET, &reset_flag);
}

int omci_lib_get_rxPower_lowerThreshold(int * lowerThreshold)
{
	if(NULL == lowerThreshold){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_RXPOWER_LOWER_THRESH, lowerThreshold);
}

int omci_lib_get_rxPower_upperThreshold(int * upperThreshold)
{
	if(NULL == upperThreshold){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_RXPOWER_UPPER_THRESH, upperThreshold);
}

int omci_lib_get_txPower_lowerThreshold(int * lowerThreshold)
{
	if(NULL == lowerThreshold){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_TXPOWER_LOWER_THRESH, lowerThreshold);
}

int omci_lib_get_txPower_upperThreshold(int * upperThreshold)
{
	if(NULL == upperThreshold){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_TXPOWER_UPPER_THRESH, upperThreshold);
}

int omci_lib_get_rdkb_voltage_minVol(int *minVol)
{
	if (NULL == minVol)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}
	
	return get_rdkb_omci_cfg_data(SHARED_VOLTAGE_MIN_VOL, minVol);
}

int omci_lib_get_rdkb_voltage_maxVol(int *maxVol)
{
	if (NULL == maxVol)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}

	return get_rdkb_omci_cfg_data(SHARED_VOLTAGE_MAX_VOL, maxVol);
}

int omci_lib_get_rdkb_bias_highBias(int *highBias)
{
	if (NULL == highBias)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}

	return get_rdkb_omci_cfg_data(SHARED_BIAS_HIGH_BIAS, highBias);
}

int omci_lib_get_rdkb_temp_minTemp(float *minTemp)
{
	if (NULL == minTemp)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}

	return get_rdkb_omci_cfg_data(SHARED_TEMP_MIN_TEMP, minTemp);
}

int omci_lib_get_rdkb_temp_maxTemp(float *maxTemp)
{
	if (NULL == maxTemp)
	{
		RETURN_FAIL_MSG("Argument is NULL.\n");
	}

	return get_rdkb_omci_cfg_data(SHARED_TEMP_MAX_TEMP, maxTemp);
}

int omci_lib_get_rdkb_veip_inst_list(omci_rdkb_veip_t * veipInstList)
{
	if(NULL == veipInstList){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_rdkb_omci_cfg_data(SHARED_VEIP_LIST, veipInstList);
}

int omci_lib_get_rdkb_tr69_inst_list(omci_rdkb_tr69_t * tr69InstList)
{
	if(NULL == tr69InstList){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_rdkb_omci_cfg_data(SHARED_TR69_LIST, tr69InstList);
}

int omci_lib_get_rdkb_tr69_entry_count(int * entryNumber)
{
	if(NULL == entryNumber){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_rdkb_omci_cfg_data(SHARED_TR69_COUNT, entryNumber);
}

int omci_lib_get_rdkb_veip_entry_count(int * entryNumber)
{
	if(NULL == entryNumber){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_rdkb_omci_cfg_data(SHARED_VEIP_COUNT, entryNumber);
}

int omci_lib_rdkb_gem_vlan_op(uint16_t gemId, int type, uint16_t vlan,RDKB_GEM_VLAN_OP opType)
{
	gem_vlan_map_t  gemVlanMap[RDKB_MAX_GEM_VLAN_MAP];
	int i = 0;
	int index = -1;
	int exitFlag = 0;
	int cnt = 0;

	if(type != RDKB_GEM_TYPE_MCAST &&  type != RDKB_GEM_TYPE_UCAST)
		RETURN_FAIL_MSG("input param is null\n");

	memcpy(gemVlanMap,_rdkb_omci_cfg_data->gemVlanMap,sizeof(gemVlanMap));
	for(i = 0; i < RDKB_MAX_GEM_VLAN_MAP; i++){
		if((gemVlanMap[i].gemId == gemId && gemVlanMap[i].type == type) || (gemVlanMap[i].type == RDKB_GEM_TYPE_MCAST && type == RDKB_GEM_TYPE_MCAST)){
			index = i;
			break;
		}
	}
	if(index == -1){
		for(i = 0; i < RDKB_MAX_GEM_VLAN_MAP; i++){
			if(gemVlanMap[i].gemId == RDKB_INVALID_GEM_ID){
				gemVlanMap[i].gemId = gemId;
				index = i;
				break;
			}
		}
	}
	if(index ==  -1){
		RETURN_FAIL_MSG("gem vlan mapping table len not enought\n");
	}

	gemVlanMap[index].type = type;
	switch(opType){
		case RDKB_GEM_VLAN_OP_ADD:
			for(i = 0; i< RDKB_GEM_MAX_VLAN_NUM; i++){
				if(gemVlanMap[index].vlanList[i] == vlan){
					exitFlag = 1;
					break;
				}
			}
			if(exitFlag == 0){
				for(i = 0; i< RDKB_GEM_MAX_VLAN_NUM; i++){
					if(gemVlanMap[index].vlanList[i] == RDKB_INVALID_VLAN_ID){
						gemVlanMap[index].vlanList[i] = vlan;
						break;
					}
				}
			}
			break;
		case RDKB_GEM_VLAN_OP_REMOVE:
			for(i = 0; i< RDKB_GEM_MAX_VLAN_NUM; i++){
				if(gemVlanMap[index].vlanList[i] == vlan){
					gemVlanMap[index].vlanList[i] = RDKB_INVALID_VLAN_ID;
					break;
				}
			}
			//sort again
			cnt = 0;
			for(i = 0; i< RDKB_GEM_MAX_VLAN_NUM; i++){
				if(gemVlanMap[index].vlanList[i] != RDKB_INVALID_VLAN_ID){
					gemVlanMap[index].vlanList[cnt++] = gemVlanMap[index].vlanList[i];
					gemVlanMap[index].vlanList[i] = RDKB_INVALID_VLAN_ID;
					break;
				}
			}
			break;
		case RDKB_GEM_VLAN_OP_CLEAR:
			gemVlanMap[index].gemId = RDKB_INVALID_GEM_ID;
			gemVlanMap[index].type = RDKB_GEM_TYPE_MAX;
			for(i = 0; i< RDKB_GEM_MAX_VLAN_NUM; i++){
				gemVlanMap[index].vlanList[i] = RDKB_INVALID_VLAN_ID;
			}
			break;
		default :
			break;
	}
	LIB_GPON_TRACE("%s [%d] gemId %d,type %d,vlan %u,opType%d success\n",__FUNCTION__,__LINE__,gemId,type,vlan,opType);

	return set_rdkb_omci_cfg_data(SHARED_GEM_VLAN_MAP, gemVlanMap);
}

int omci_lib_set_rdkb_gem_vlan(uint16_t gemId, int type, uint16_t *vlanList,int len)
{
	gem_vlan_map_t  gemVlanMap[RDKB_MAX_GEM_VLAN_MAP];
	int i = 0;
	int index = -1;

	if(vlanList == NULL || len < sizeof(gemVlanMap[0].vlanList)  || type >= RDKB_GEM_TYPE_MAX)
			RETURN_FAIL_MSG("input param is null\n");

	memcpy(gemVlanMap,_rdkb_omci_cfg_data->gemVlanMap,sizeof(gemVlanMap));
	for(i = 0; i < RDKB_MAX_GEM_VLAN_MAP; i++){
		if(gemVlanMap[i].gemId == gemId){
			index = i;
			break;
		}
	}
	if(index == -1){
		for(i = 0; i < RDKB_MAX_GEM_VLAN_MAP; i++){
			if(gemVlanMap[i].gemId == RDKB_INVALID_GEM_ID){
				index = i;
				break;
			}
		}
	}

	if(index ==  -1){
		RETURN_FAIL_MSG("gem vlan mapping table len not enought\n");
	}

	//set the gemVlanMap
	gemVlanMap[i].gemId = gemId;
	gemVlanMap[i].type = type;
	memcpy(gemVlanMap[i].vlanList,vlanList,sizeof(gemVlanMap[i].vlanList));

	LIB_GPON_TRACE("%s [%d] gemId=%d,type=%d,vlanId[0]=%u success\n",__FUNCTION__,__LINE__,gemId,type,gemVlanMap[i].vlanList[0]);

	return set_rdkb_omci_cfg_data(SHARED_GEM_VLAN_MAP, gemVlanMap);
}

int omci_lib_get_rdkb_gem_vlan(uint16_t gemId, int *type, uint16_t *vlanList,int len){
	gem_vlan_map_t  gemVlanMap[RDKB_MAX_GEM_VLAN_MAP];
	int i = 0;

	if(vlanList == NULL || len < sizeof(gemVlanMap[0].vlanList))
		RETURN_FAIL_MSG("input param is null\n");

	get_rdkb_omci_cfg_data(SHARED_GEM_VLAN_MAP, gemVlanMap);

	for(i = 0; i < RDKB_MAX_GEM_VLAN_MAP; i++){
		if(gemVlanMap[i].gemId == gemId){
			*type = gemVlanMap[i].type;
			memcpy(vlanList,gemVlanMap[i].vlanList,sizeof(gemVlanMap[i].vlanList));
			return 0;
		}
	}

	LIB_GPON_ERROR("%s [%d] gemId=%d failed\n",__FUNCTION__,__LINE__,gemId);
	return -1;
}

/******************************************************************************
 Descriptor:    It's used to set OMCI FSM Condition Bit.
 Input Args:    fsmCondition: uint8_t.
 				fsmConditionMask: uint8_t.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_omci_fsm_cond_by_bit(uint8_t fsmCondition,uint8_t fsmConditionMask)
{
	omci_fsm_cond_data_t condition_data ={0};

	condition_data.condition = fsmCondition;
	condition_data.condition_mask = fsmConditionMask;

	return set_omci_internal_data(SHARED_FSM_COND,&condition_data);
}

/******************************************************************************
 Descriptor:    It's used to get OMCI FSM Condition.
 Input Args:    fsmCondition: uint8_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_omci_fsm_cond(uint8_t *fsmCondition)
{
	omci_fsm_cond_data_t condition_data ={0};
	int ret = 0;
	
	if(NULL == fsmCondition){
		RETURN_FAIL_MSG("input param is null\n");
	}
	ret = get_omci_internal_data(SHARED_FSM_COND,&condition_data);
	if (ret != 0){
		RETURN_FAIL_MSG("get_omci_internal_data fail\n");
	}
	*fsmCondition = condition_data.condition;

	return ret;
}

void omci_lib_cfg_data_done(void)
{
	omci_lib_set_omci_fsm_cond_by_bit(CONDITION_CFG_DONE,CONDITION_CFG_DONE);
}

void omci_lib_notify_onu_ready(void)
{
	omci_lib_set_omci_fsm_cond_by_bit(CONDITION_ONU_READY,CONDITION_ONU_READY);
}
void omci_lib_notify_re_config(void)
{
	omci_lib_set_omci_fsm_cond_by_bit(CONDITION_RE_CONFIG,CONDITION_RE_CONFIG);
}


/******************************************************************************
 Descriptor:    It's used to set omci dbg level.
 Input Args:    DebugLevel:
			   #define OMCI_DEBUG_LEVEL_NO_MSG		0
			   #define OMCI_DEBUG_LEVEL_ERROR		1
			   #define OMCI_DEBUG_LEVEL_WARN		2
			   #define OMCI_DEBUG_LEVEL_TRACE		3
			   #define OMCI_DEBUG_LEVEL_DEBUG		4
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_omci_dbg_level(unsigned char DebugLevel)
{
	return set_omci_internal_data(SHARED_DBG_LEVEL,&DebugLevel);
}


/******************************************************************************
 Descriptor:    It's used to set omci lib dbg level.
 Input Args:    DebugLevel:
			   #define OMCI_DEBUG_LEVEL_NO_MSG		0
			   #define OMCI_DEBUG_LEVEL_ERROR		1
			   #define OMCI_DEBUG_LEVEL_WARN		2
			   #define OMCI_DEBUG_LEVEL_TRACE		3
			   #define OMCI_DEBUG_LEVEL_DEBUG		4
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_omci_lib_dbg_level(unsigned char DebugLevel)
{
	if(DebugLevel > OMCI_LIB_DEBUG_LEVEL_DEBUG)
		return -1;

	set_omci_internal_data(SHARED_LIB_DBG_LEVEL,&DebugLevel);
	omci_lib_dbg_flag = DebugLevel;
	return 0;
}

/******************************************************************************
 Descriptor:    It's used to set LanDebug.
 Input Args:    LanDebug: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_lan_debug(unsigned char LanDebug)
{
	return set_omci_internal_data(SHARED_LAN_DBG,&LanDebug);
}


/******************************************************************************
 Descriptor:    It's used to use tcapi command set ONU enhanced psk.
 Input Args:    enhanced_bsk: char pointer.
 Ret Value: success: ECONET_E_SUCCESS
               fail: ECONET_E_FAIL
******************************************************************************/
int omci_lib_set_cfg_enhanced_psk(unsigned char *cfg_psk)
{
	char buffer[52];
	int tmpPSK[PRESHARED_KEY_LEN] = {0};
	unsigned char enhanced_psk[PRESHARED_KEY_LEN] = {0};
	int i = 0;
	
	if(NULL == cfg_psk){
		RETURN_FAIL_MSG("cfg set psk input param is null\n");
	}
	memcpy(buffer,cfg_psk,sizeof(buffer));
	sscanf(buffer, "%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", 
		&tmpPSK[0], &tmpPSK[1], &tmpPSK[2], &tmpPSK[3], &tmpPSK[4], &tmpPSK[5], &tmpPSK[6], &tmpPSK[7], 
		&tmpPSK[8], &tmpPSK[9], &tmpPSK[10], &tmpPSK[11], &tmpPSK[12], &tmpPSK[13], &tmpPSK[14], &tmpPSK[15]);
	for(i = 0; i < PRESHARED_KEY_LEN; i++){
		if((tmpPSK[i] >= 0) && (tmpPSK[i] <= 255))
			enhanced_psk[i] = tmpPSK[i];
		else{
			RETURN_FAIL_MSG("Invalid PSK value\n");
		}
	}
    if(OMCI_LIB_FAIL == omci_lib_set_enhanced_psk(enhanced_psk))
    {
		RETURN_FAIL_MSG("Exec.set psk Failed\n\n");
    }
    RETURN_SUCCESS;
}

/******************************************************************************
 Descriptor:    It's used to set ONU enhanced psk.
 Input Args:    enhanced_psk: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_enhanced_psk(unsigned char *enhanced_psk)
{
	if(NULL == enhanced_psk){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_cfg_data(SHARED_ENHANCED_PSK,enhanced_psk);
}

/******************************************************************************
 Descriptor:    It's used to set ONU version.
 Input Args:    version: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_onu_version(char *version)
{
	if(NULL == version){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_cfg_data(SHARED_ONU_VER,version);
}

/******************************************************************************
 Descriptor:    It's used to set vendor ID.
 Input Args:    VendorId: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_vendor_id(char *VendorId)
{
	if(NULL == VendorId){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_cfg_data(SHARED_VENDOR_ID,VendorId);
}

/******************************************************************************
 Descriptor:    It's used to set equipmentId.
 Input Args:    equipmentId: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_equipment_id(char *equipmentId)
{
	if(NULL == equipmentId){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_cfg_data(SHARED_EQUIPMENT_ID,equipmentId);
}

/******************************************************************************
 Descriptor:    It's used to set operatorID_cap.
 Input Args:    operatorID_cap: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_operator_id_cap(char *operatorID_cap)
{
	if(NULL == operatorID_cap){
		RETURN_FAIL_MSG("input param is null\n");
	}
	
	return set_omci_internal_data(SHARED_OPERATOR_ID_CAP,operatorID_cap);
}

/******************************************************************************
 Descriptor:    It's used to set operatorID_auth.
 Input Args:    operatorID_auth: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_operator_id_auth(char *operatorID_auth)
{
	if(NULL == operatorID_auth){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_internal_data(SHARED_OPERATOR_ID_AUTH,operatorID_auth);
}

/******************************************************************************
 Descriptor:    It's used to clear GPON MAC serial number.
 Input Args:    psn: serial number.
 Ret Value: success: OMCI_LIB_SUCCESS
                       fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_sn_mem(unsigned char *psn)
{
	if(NULL == psn){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return set_omci_cfg_data(SHARED_SN,psn);
}
/******************************************************************************
 Descriptor:    It's used to set Password.
 Input Args:    LOID_Password: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_passwd_mem(char *password)
{
	if(NULL == password){
		RETURN_FAIL_MSG("input param is null\n");
	}
	
	return set_omci_cfg_data(SHARED_PASSWORD,password);
}


/******************************************************************************
 Descriptor:    It's used to get RegId.
 Input Args:    Loid: char pointer,size:the size of RegId buffer,it must be no less than GPON_REG_ID_LENS.
 Ret Value: success: ECONET_E_SUCCESS
               fail: ECONET_E_FAIL
******************************************************************************/
int omci_lib_get_regid_mem(char *regid, unsigned int size)
{
	if(size < OMCI_REG_ID_LENS)
		RETURN_FAIL_MSG("size is less than XGPON_regid_LENS\n");
	
	if(NULL == regid){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(regid,0,OMCI_REG_ID_LENS);
	return get_omci_cfg_data(SHARED_REGID,regid);
}

/******************************************************************************
 Descriptor:    It's used to set Loid.
 Input Args:    LOID: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_loid(char *Loid)
{
	if(NULL == Loid){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_internal_data(SHARED_LOID,Loid);
}

/******************************************************************************
 Descriptor:    It's used to set LOID_Password.
 Input Args:    LOID_Password: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_loid_password(char *LOID_Password)
{
	if(NULL == LOID_Password){
		RETURN_FAIL_MSG("input param is null\n");
	}
	
	return set_omci_internal_data(SHARED_LOID_PASSWORD,LOID_Password);
}

/******************************************************************************
 Descriptor:    It's used to set linkMode.
 Input Args:    linkMode: char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_link_mode(char linkMode)
{
	return set_omci_cfg_data(SHARED_LINK_MODE,&linkMode);
}

/******************************************************************************
 Descriptor:    It's used to set usqMode
 Input Args:    usQMode: char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_usq_mode(char usQMode)
{
	return set_omci_cfg_data(SHARED_USQ_MODE,&usQMode);
}

/******************************************************************************
 Descriptor:    It's used to set vendorProCode.
 Input Args:    vendorProCode: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_vendor_pro_code(unsigned short vendorProCode)
{	
	return set_omci_cfg_data(SHARED_VENDOR_PRO_CODE,&vendorProCode);
}

/******************************************************************************
 Descriptor:    It's used to set omccVersion.
 Input Args:    omccVersion: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_omcc_version(unsigned char omccVersion)
{
	return set_omci_cfg_data(SHARED_OMCC_VERSION,&omccVersion);
}

/******************************************************************************
 Descriptor:    It's used to set tmOption.
 Input Args:    tmOption: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_tm_option(unsigned char tmOption)
{	
	return set_omci_cfg_data(SHARED_TM_OPTION,&tmOption);
}

/******************************************************************************
 Descriptor:    It's used to set onuSurvivalTime.
 Input Args:    onuSurvivalTime: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_survival_time(unsigned char onuSurvivalTime)
{	
	return set_omci_cfg_data(SHARED_SURVIVAL_TIME,&onuSurvivalTime);
}


/******************************************************************************
 Descriptor:    It's used to set extendedTcLayer.
 Input Args:    extendedTcLayer: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_extended_tclayer(unsigned char extendedTcLayer)
{
	return set_omci_cfg_data(SHARED_EXT_TCLAYER,&extendedTcLayer);
}


/******************************************************************************
 Descriptor:    It's used to set eventMask.
 Input Args:    eventMask: unsigned int.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_event_mask(unsigned int eventMask)
{
	return set_omci_cfg_data(SHARED_EVENT_MONITOR_MASK,&eventMask);
}

/******************************************************************************
 Descriptor:    It's used to set securityCap.
 Input Args:    securityCap: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_security_cap(unsigned char securityCap)
{
	return set_omci_cfg_data(SHARED_SECURITY_CAP,&securityCap);
}


/******************************************************************************
 Descriptor:    It's used to set totalTSNum.
 Input Args:    totalTSNum: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_total_ts_num(unsigned char totalTSNum)
{	
	return set_omci_cfg_data(SHARED_TS_NUM,&totalTSNum);
}

/******************************************************************************
 Descriptor:    It's used to set totalPQNum.
 Input Args:    totalPQNum: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_total_pq_num(unsigned short totalPQNum)
{	
	return set_omci_cfg_data(SHARED_PQ_NUM,&totalPQNum);
}

/******************************************************************************
 Descriptor:    It's used to set totalGEMPortNum.
 Input Args:    totalGEMPortNum: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_total_gemport_num(unsigned short totalGEMPortNum)
{
	return set_omci_cfg_data(SHARED_GEM_NUM,&totalGEMPortNum);
}

/******************************************************************************
 Descriptor:    It's used to set connectivityCap.
 Input Args:    connectivityCap: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_connectivity_cap(unsigned short connectivityCap)
{
	return set_omci_cfg_data(SHARED_CONNET_CAP,&connectivityCap);
}

/******************************************************************************
 Descriptor:    It's used to set qoSConfFlex.
 Input Args:    qoSConfFlex: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_qos_conf_flex(unsigned short qoSConfFlex)
{
	return set_omci_cfg_data(SHARED_QOS_CONF_FLEX,&qoSConfFlex);
}

/******************************************************************************
 Descriptor:    It's used to set VoIPbyTR069.
 Input Args:    VoIPbyTR069: char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_voip_by_tr069(char VoIPbyTR069)
{
	return set_omci_internal_data(SHARED_VIOP_BY_TR069,&VoIPbyTR069);
}

/******************************************************************************
 Descriptor:    It's used to set VoIP time Sep Enable.
 Input Args:    VoIPSepEn: char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_voip_sep_en(char VoIPSepEn)
{
	return set_omci_internal_data(SHARED_VIOP_SEP_EN,&VoIPSepEn);
}

/******************************************************************************
 Descriptor:    It's used to set SpecVersion.
 Input Args:    SpecVersion: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_spec_version(unsigned char SpecVersion)
{
	return set_omci_internal_data(SHARED_SPEC_VER,&SpecVersion);
}

/******************************************************************************
 Descriptor:    It's used to set ONU_PowerCtr.
 Input Args:    ONU_PowerCtr: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_onu_power_ctrl(unsigned char ONU_PowerCtr)
{
	return set_omci_internal_data(SHARED_ONU_POWER_CTRL,&ONU_PowerCtr);
}

/******************************************************************************
 Descriptor:    It's used to set AuthStatus.
 Input Args:    AuthStatus: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_auth_status(unsigned char AuthStatus)
{
	return set_omci_internal_data(SHARED_AUTH_STATUS,&AuthStatus);
}

/******************************************************************************
 Descriptor:    It's used to set srIndication.
 Input Args:    srIndication: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_sr_indication(unsigned char srIndication)
{	
	return set_omci_cfg_data(SHARED_SR_INDICT,&srIndication);
}

/******************************************************************************
 Descriptor:    It's used to set totalTcontNum.
 Input Args:    totalTcontNum: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_total_tcont_num(unsigned short totalTcontNum)
{
	return set_omci_cfg_data(SHARED_TCONT_NUM,&totalTcontNum);
}


/******************************************************************************
 Descriptor:    It's used to set gemBlockLength.
 Input Args:    gemBlockLength: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_gem_block_length(unsigned short gemBlockLength)
{	
	return set_omci_cfg_data(SHARED_GEM_BLOCK_LEN,&gemBlockLength);
}


/******************************************************************************
 Descriptor:    It's used to set onuResponseTime.
 Input Args:    onuResponseTime: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_onu_response_time(unsigned short onuResponseTime)
{
	return set_omci_cfg_data(SHARED_ONU_RES_TIME,&onuResponseTime);
}

/******************************************************************************
 Descriptor:    It's used to set conReqPort.
 Input Args:    conReqPort: unsigned short.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_con_req_port(unsigned short conReqPort)
{	
	return set_omci_internal_data(SHARED_CON_REQ_PORT,&conReqPort);
}

/******************************************************************************
 Descriptor:    It's used to set max_ports & port_id.
 Input Args:    max_ports: signed char.
 				port_id: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_max_ports_list(signed char max_ports,int *port_id)
{
	if(NULL == port_id){
		RETURN_FAIL_MSG("input param is null\n");
	}

	if(set_omci_cfg_data(SHARED_MAX_PORTS, &max_ports) == OMCI_LIB_FAIL){
		RETURN_FAIL_MSG("SET MAX PORTS ERROR!\n");
	}
	
	return set_omci_cfg_data(SHARED_PORT_LIST,port_id);
}

/******************************************************************************
 Descriptor:    It's used to set onuType.
 Input Args:    onuType: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_onu_type_mem(unsigned char onuType)
{
	return set_omci_cfg_data(SHARED_ONU_TYPE,&onuType);
}

/******************************************************************************
 Descriptor:    It's used to get omci dbg level.
 Input Args:    DebugLevel: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_omci_dbg_level(unsigned char *DebugLevel)
{
	if(NULL == DebugLevel){
		RETURN_FAIL_MSG("input param is null\n");
	}
	
	return get_omci_internal_data(SHARED_DBG_LEVEL,DebugLevel);
}


/******************************************************************************
 Descriptor:    It's used to get omci lib dbg level.
 Input Args:    DebugLevel:
			   #define OMCI_DEBUG_LEVEL_NO_MSG		0
			   #define OMCI_DEBUG_LEVEL_ERROR		1
			   #define OMCI_DEBUG_LEVEL_WARN		2
			   #define OMCI_DEBUG_LEVEL_TRACE		3
			   #define OMCI_DEBUG_LEVEL_DEBUG		4
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_omci_lib_dbg_level(unsigned char *DebugLevel)
{
	if(DebugLevel == NULL)
		return -1;

	get_omci_internal_data(SHARED_LIB_DBG_LEVEL,DebugLevel);
	return 0;
}

/******************************************************************************
 Descriptor:    It's used to get LanDebug.
 Input Args:    LanDebug: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_lan_debug(unsigned char *LanDebug)
{
	if(NULL == LanDebug){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_LAN_DBG,LanDebug);
}

/******************************************************************************
 Descriptor:    It's used to get ONU enhanced psk.
 Input Args:    enhanced_psk: char pointer,size:the size of enhanced_psk buffer, it must be no less than PRESHARED_KEY_LEN
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_enhanced_psk(unsigned char *enhanced_psk, unsigned int size)
{
	if(size < PRESHARED_KEY_LEN)
		RETURN_FAIL_MSG("size is less than PRESHARED_KEY_LEN\n");
	
	if(NULL == enhanced_psk){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(enhanced_psk,0,PRESHARED_KEY_LEN);
	return get_omci_cfg_data(SHARED_ENHANCED_PSK,enhanced_psk);
}

/******************************************************************************
 Descriptor:    It's used to get ONU version.
 Input Args:    version: char pointer,size:the size of version buffer,it must be no less than OMCI_VERSION_LENS
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_onu_version(char *version, unsigned int size)
{
	if(size < OMCI_VERSION_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_VERSION_LENS\n");
	
	if(NULL == version){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(version,0,OMCI_VERSION_LENS);
	return get_omci_cfg_data(SHARED_ONU_VER,version);
}

/******************************************************************************
 Descriptor:    It's used to get vendor ID.
 Input Args:    VendorId: char pointer,size:the size of VendorId buffer,it must be no less than OMCI_VENDOR_ID_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_vendor_id(char *VendorId, unsigned int size)
{
	if(size < OMCI_VENDOR_ID_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_VENDOR_ID_LENS\n");
	
	if(NULL == VendorId){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(VendorId,0,OMCI_VENDOR_ID_LENS);
	return get_omci_cfg_data(SHARED_VENDOR_ID,VendorId);
}

/******************************************************************************
 Descriptor:    It's used to get equipmentId.
 Input Args:    equipmentId: char pointer,size:the size of equipmentId buffer,it must be no less than OMCI_EQUIPMENTID_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_equipment_id(char *equipmentId, unsigned int size)
{
	if(size < OMCI_EQUIPMENTID_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_EQUIPMENTID_LENS\n");
	
	if(NULL == equipmentId){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(equipmentId,0,OMCI_EQUIPMENTID_LENS);
	return get_omci_cfg_data(SHARED_EQUIPMENT_ID,equipmentId);
}

/******************************************************************************
 Descriptor:    It's used to get operatorID_cap.
 Input Args:    operatorID_cap: char pointer,size:the size of operatorID_cap buffer,it must be no less than OMCI_OPERATOR_ID_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_operator_id_cap(char *operatorID_cap, unsigned int size)
{
	if(size < OMCI_OPERATOR_ID_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_OPERATOR_ID_LENS\n");
	
	if(NULL == operatorID_cap){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(operatorID_cap,0,OMCI_OPERATOR_ID_LENS);
	return get_omci_internal_data(SHARED_OPERATOR_ID_CAP,operatorID_cap);
}

/******************************************************************************
 Descriptor:    It's used to get operatorID_auth.
 Input Args:    operatorID_auth: char pointer,size:the size of operatorID_auth buffer,it must be no less than OMCI_OPERATOR_ID_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_operator_id_auth(char *operatorID_auth, unsigned int size)
{
	if(size < OMCI_OPERATOR_ID_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_OPERATOR_ID_LENS\n");
	
	if(NULL == operatorID_auth){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(operatorID_auth,0,OMCI_OPERATOR_ID_LENS);
	return get_omci_internal_data(SHARED_OPERATOR_ID_AUTH,operatorID_auth);
}

/******************************************************************************
 Descriptor:    It's used to get sn.
 Input Args:    Loid: char pointer,size:the size of SN buffer,it must be no less than GPON_SN_MEM_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_sn_mem(char *sn, unsigned int size)
{
	if(size < OMCI_SN_MEM_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_SN_MEM_LENS(16Bypes)\n");
	
	if(NULL == sn){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(sn,0,OMCI_SN_MEM_LENS);
	return get_omci_cfg_data(SHARED_SN,sn);
}

/******************************************************************************
 Descriptor:    It's used to get Password.
 Input Args:    Loid: char pointer,size:the size of Password buffer,it must be no less than GPON_PASSWD_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_passwd_mem(char *password, unsigned int size)
{
	if(size < OMCI_PASSWD_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_PASSWD_LENS(10Bytes)\n");
	
	if(NULL == password){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(password,0,OMCI_PASSWD_LENS);
	return get_omci_cfg_data(SHARED_PASSWORD,password);
}

/******************************************************************************
 Descriptor:    It's used to get LOID.
 Input Args:    Loid: char pointer,size:the size of Loid buffer,it must be no less than OMCI_LOID_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_loid(char *Loid, unsigned int size)
{
	if(size < OMCI_LOID_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_LOID_LENS\n");
	
	if(NULL == Loid){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(Loid,0,OMCI_LOID_LENS);
	return get_omci_internal_data(SHARED_LOID,Loid);
}

/******************************************************************************
 Descriptor:    It's used to get LOID_Password.
 Input Args:    LOID_Password: char pointer,size:the size of LOID_Password buffer,it must be no less than OMCI_LOID_PASSWORD_LENS.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_loid_password(char *LOID_Password, unsigned int size)
{
	if(size < OMCI_LOID_PASSWORD_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_LOID_PASSWORD_LENS\n");
	
	if(NULL == LOID_Password){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(LOID_Password,0,OMCI_LOID_PASSWORD_LENS);
	return get_omci_internal_data(SHARED_LOID_PASSWORD,LOID_Password);
}

/******************************************************************************
 Descriptor:    It's used to get linkMode.
 Input Args:    linkMode: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_link_mode(onu_link_mode_t *linkMode)
{
	if(NULL == linkMode){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_LINK_MODE,linkMode);
}

/******************************************************************************
 Descriptor:    It's used to get usQMode
 Input Args:    usQMode: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_usq_mode(char *usQMode)
{
	if(NULL == usQMode){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_USQ_MODE,usQMode);
}
/******************************************************************************
 Descriptor:    It's used to get vendorProCode.
 Input Args:    vendorProCode: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_vendor_pro_code(unsigned short *vendorProCode)
{
	if(NULL == vendorProCode){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_VENDOR_PRO_CODE,vendorProCode);
}

/******************************************************************************
 Descriptor:    It's used to get omccVersion.
 Input Args:    omccVersion: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_omcc_version(unsigned char *omccVersion)
{
	if(NULL == omccVersion){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_OMCC_VERSION,omccVersion);
}

/******************************************************************************
 Descriptor:    It's used to get tmOption.
 Input Args:    tmOption: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_tm_option(unsigned char *tmOption)
{
	if(NULL == tmOption){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_TM_OPTION,tmOption);
}

/******************************************************************************
 Descriptor:    It's used to get onuSurvivalTime.
 Input Args:    onuSurvivalTime: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_survival_time(unsigned char *onuSurvivalTime)
{
	if(NULL == onuSurvivalTime){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_SURVIVAL_TIME,onuSurvivalTime);
}


/******************************************************************************
 Descriptor:    It's used to get extendedTcLayer.
 Input Args:    extendedTcLayer: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_extended_tclayer(unsigned char *extendedTcLayer)
{
	if(NULL == extendedTcLayer){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_EXT_TCLAYER,extendedTcLayer);
}

/******************************************************************************
 Descriptor:    It's used to get eventMask.
 Input Args:    eventMask: unsigned int pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_event_mask(unsigned int *eventMask)
{
	if(NULL == eventMask){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_EVENT_MONITOR_MASK,eventMask);
}

/******************************************************************************
 Descriptor:    It's used to get securityCap.
 Input Args:    securityCap: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_security_cap(unsigned char *securityCap)
{
	if(NULL == securityCap){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_SECURITY_CAP,securityCap);
}


/******************************************************************************
 Descriptor:    It's used to get totalTSNum.
 Input Args:    totalTSNum: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_total_ts_num(unsigned char *totalTSNum)
{
	if(NULL == totalTSNum){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_TS_NUM,totalTSNum);
}

/******************************************************************************
 Descriptor:    It's used to get totalPQNum.
 Input Args:    totalPQNum: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_total_pq_num(unsigned short *totalPQNum)
{
	if(NULL == totalPQNum){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_PQ_NUM,totalPQNum);
}

/******************************************************************************
 Descriptor:    It's used to get totalGEMPortNum.
 Input Args:    totalGEMPortNum: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_total_gemport_num(unsigned short *totalGEMPortNum)
{
	if(NULL == totalGEMPortNum){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_GEM_NUM,totalGEMPortNum);
}

/******************************************************************************
 Descriptor:    It's used to get connectivityCap.
 Input Args:    connectivityCap: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_connectivity_cap(unsigned short *connectivityCap)
{
	if(NULL == connectivityCap){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_CONNET_CAP,connectivityCap);
}

/******************************************************************************
 Descriptor:    It's used to get qoSConfFlex.
 Input Args:    qoSConfFlex: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_qos_conf_flex(unsigned short *qoSConfFlex)
{
	if(NULL == qoSConfFlex){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_QOS_CONF_FLEX,qoSConfFlex);
}

/******************************************************************************
 Descriptor:    It's used to get VoIPbyTR069.
 Input Args:    VoIPbyTR069: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_voip_by_tr069(char *VoIPbyTR069)
{
	if(NULL == VoIPbyTR069){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_VIOP_BY_TR069,VoIPbyTR069);
}

/******************************************************************************
 Descriptor:    It's used to get VoIP Time Sep Enable.
 Input Args:    VoIPSepEn: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_voip_sep_en(char *VoIPSepEn)
{
	if(NULL == VoIPSepEn){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_VIOP_SEP_EN,VoIPSepEn);
}

/******************************************************************************
 Descriptor:    It's used to get SpecVersion.
 Input Args:    SpecVersion: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_spec_version(unsigned char *SpecVersion)
{
	if(NULL == SpecVersion){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_SPEC_VER,SpecVersion);
}

/******************************************************************************
 Descriptor:    It's used to get ONU_PowerCtr.
 Input Args:    ONU_PowerCtr: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_onu_power_ctrl(unsigned char *ONU_PowerCtr)
{
	if(NULL == ONU_PowerCtr){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_ONU_POWER_CTRL,ONU_PowerCtr);
}

/******************************************************************************
 Descriptor:    It's used to get AuthStatus.
 Input Args:    AuthStatus: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_auth_status(unsigned char *AuthStatus)
{
	if(NULL == AuthStatus){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_AUTH_STATUS,AuthStatus);
}

/******************************************************************************
 Descriptor:    It's used to get srIndication.
 Input Args:    srIndication: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_sr_indication(unsigned char *srIndication)
{
	if(NULL == srIndication){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_SR_INDICT,srIndication);
}

/******************************************************************************
 Descriptor:    It's used to get totalTcontNum.
 Input Args:    totalTcontNum: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_total_tcont_num(unsigned short *totalTcontNum)
{
	if(NULL == totalTcontNum){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_TCONT_NUM,totalTcontNum);
}

/******************************************************************************
 Descriptor:    It's used to get gemBlockLength.
 Input Args:    gemBlockLength: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_gem_block_length(unsigned short *gemBlockLength)
{
	if(NULL == gemBlockLength){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_GEM_BLOCK_LEN,gemBlockLength);
}

/******************************************************************************
 Descriptor:    It's used to get onuResponseTime.
 Input Args:    onuResponseTime: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_onu_response_time(unsigned short *onuResponseTime)
{
	if(NULL == onuResponseTime){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_ONU_RES_TIME,onuResponseTime);
}

/******************************************************************************
 Descriptor:    It's used to get conReqPort.
 Input Args:    conReqPort: unsigned short pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_con_req_port(unsigned short *conReqPort)
{
	if(NULL == conReqPort){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_CON_REQ_PORT,conReqPort);
}

/******************************************************************************
 Descriptor:    It's used to get max ports.
 Input Args:    max_ports: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/

int omci_lib_get_max_ports(signed char *max_ports)
{
	if(NULL == max_ports){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_MAX_PORTS,max_ports);
}


/******************************************************************************
 Descriptor:    It's used to get max ports.
 Input Args:    port_id: int array pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/

int omci_lib_get_port_list(int *port_id)
{
	if(NULL == port_id){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_PORT_LIST,port_id);
}

/******************************************************************************
 Descriptor:    It's used to get onuType.
 Input Args:    onuType: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_onu_type_mem(unsigned char *onuType)
{
	if(NULL == onuType){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_ONU_TYPE,onuType);
}

/******************************************************************************
 Descriptor:    It's used to get romfile_load_flag.
 Input Args:    romfile_load_flag: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_oam_lib_get_romfile_load_flag(unsigned char *romfile_load_flag)
{
	if(romfile_load_flag ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return get_omci_internal_data(SHARED_ROMFILE_LOAD_FLAG,romfile_load_flag);
}

/******************************************************************************
 Descriptor:    It's used to set romfile_load_flag.
 Input Args:    romfile_load_flag: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_oam_lib_set_romfile_load_flag(unsigned char romfile_load_flag)
{
	return set_omci_internal_data(SHARED_ROMFILE_LOAD_FLAG,&romfile_load_flag);
}

/******************************************************************************
 Descriptor:    It's used to get EmergencyState.
 Input Args:    EmergencyState: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_onu_emergency(unsigned char *EmergencyState)
{
	if(EmergencyState ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return get_omci_internal_data(SHARED_EMERGENCY_STATE,EmergencyState);
}

/******************************************************************************
 Descriptor:    It's used to get oltType.
 Input Args:    oltType: char pointer.
 Ret Value: success: ECONET_E_SUCCESS
               fail: ECONET_E_FAIL
******************************************************************************/
int omci_lib_get_olt_type(char *oltType, unsigned int size)
{
    if(size < OMCI_OLT_TYPE_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_OLT_TYPE_LENS\n");
	if(NULL == oltType){
		RETURN_FAIL_MSG("input param is null\n");
	}
	memset(oltType,0,OMCI_OLT_TYPE_LENS);
	return get_omci_internal_data(SHARED_OLT_TYPE,oltType);
}

/******************************************************************************
 Descriptor:    It's used to set emergencyState.
 Input Args:    EmergencyState: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_onu_emergency(unsigned char EmergencyState)
{
	return set_omci_internal_data(SHARED_EMERGENCY_STATE,&EmergencyState);
}

/******************************************************************************
 Descriptor:    It's used to set oltType.
 Input Args:    oltType: char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_olt_type(char *oltType)
{
	return set_omci_internal_data(SHARED_OLT_TYPE, oltType);
}

/******************************************************************************
 Descriptor:    It's used to get compile option.
 Input Args:    compileOption: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_compile_option(CompileOp_t *compileOption)
{
	if(compileOption ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return get_omci_internal_data(SHARED_COMPILE_OPTION,compileOption);
}

/******************************************************************************
 Descriptor:    It's used to set compile option.
 Input Args:    compileOption: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_compile_option(CompileOp_t *compileOption)
{
	if(compileOption ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_internal_data(SHARED_COMPILE_OPTION,compileOption);
}

/******************************************************************************
 Descriptor:    It's used to omci attribute default value.
 Input Args:    omciAttrDefVal: omciAttrDefVal_t struct pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_omci_attr_default_value(omciAttrDefVal_t *omciAttrDefVal)
{
	if(omciAttrDefVal ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return get_omci_internal_data(SHARED_OMCI_ATTR_DEF_VAL,omciAttrDefVal);
}

/******************************************************************************
 Descriptor:    It's used to set omci attribute default value.
 Input Args:    omciAttrDefVal: omciAttrDefVal_t struct pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_omci_attr_default_value(omciAttrDefVal_t *omciAttrDefVal)
{
	if(omciAttrDefVal ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_internal_data(SHARED_OMCI_ATTR_DEF_VAL,omciAttrDefVal);
}

/******************************************************************************
 Descriptor:    It's used to get time status message.
 Input Args:    timeStatusMsg: time_status_msg_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_time_status_msg(time_status_msg_t *timeStatusMsg)
{
	if(timeStatusMsg ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return get_omci_cfg_data(SHARED_TIME_STATUS_MSG,timeStatusMsg);
}

/******************************************************************************
 Descriptor:    It's used to set time status message.
 Input Args:    timeStatusMsg: time_status_msg_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_time_status_msg(time_status_msg_t *timeStatusMsg)
{
	return set_omci_cfg_data(SHARED_TIME_STATUS_MSG,timeStatusMsg);
}

/******************************************************************************
 Descriptor:    It's used to get FILE transfer control message.
 Input Args:    fileCtrl: file_transfer_ctrl_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_file_trans_ctrl(file_transfer_ctrl_t* fileCtrl)
{
	if(fileCtrl ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return get_omci_cfg_data(SHARED_FILE_TRANSFER_CTRL,fileCtrl);
}

/******************************************************************************
 Descriptor:    It's used to set FILE transfer control  message.
 Input Args:    fileCtrl: file_transfer_ctrl_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_file_trans_ctrl(file_transfer_ctrl_t* fileCtrl)
{
	if(fileCtrl ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_cfg_data(SHARED_FILE_TRANSFER_CTRL,fileCtrl);
}

/******************************************************************************
 Descriptor:    It's used to set Custom Self Define Vendor ID flag .
 Input Args:    flag: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_self_def_vendorId_flag(unsigned char flag)
{
	return set_omci_internal_data(SHARED_SELF_DEF_VD,&flag);
}

/******************************************************************************
 Descriptor:    It's used to GET Custom Self Define Vendor ID Flag.
 Input Args:    flag: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_self_def_vendorId_flag(unsigned char *flag)
{
    if(NULL == flag){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_SELF_DEF_VD,flag);
}

/******************************************************************************
 Descriptor:    It's used to set strict PPTP ethuni slot flag .
 Input Args:    flag: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_strict_pptp_ethuni_slot_flag(unsigned char flag)
{
	return set_omci_internal_data(SHARED_STRICT_PPTP_ETHUNI_SLOT,&flag);
}

/******************************************************************************
 Descriptor:    It's used to GET strict PPTP ethuni slot Flag.
 Input Args:    flag: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_strict_pptp_ethuni_slot_flag(unsigned char *flag)
{
    if(NULL == flag){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_internal_data(SHARED_STRICT_PPTP_ETHUNI_SLOT,flag);
}

/******************************************************************************
 Descriptor:    It's used to get IPHOST MAC Address.
 Input Args:    mac : char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_iphost_mac(unsigned char *mac, unsigned int size)
{
    if(size < OMCI_IPHOST_MAC_LENS)
		RETURN_FAIL_MSG("size is less than OMCI_IPHOST_MAC_LENS\n");
	
	if(NULL == mac){
		RETURN_FAIL_MSG("input param is null\n");
	}
    memset(mac,0,OMCI_IPHOST_MAC_LENS);
	return get_omci_cfg_data(SHARED_IPHOST_MAC,mac);
}

/******************************************************************************
 Descriptor:    It's used to set IPHOST MAC Address.
 Input Args:    mac: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_iphost_mac(unsigned char *mac)
{
	if(NULL == mac){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return set_omci_cfg_data(SHARED_IPHOST_MAC,mac);
}

/******************************************************************************
 Descriptor:    It's used to set IPHOST Instance Number.
 Input Args:    num: unsgined char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_iphost_num(unsigned char num)
{
	return set_omci_cfg_data(SHARED_IPHOST_NUM,&num);
}


/******************************************************************************
 Descriptor:    It's used to get IPHOST Instance Number.
 Input Args:    num: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_iphost_num(unsigned char *num)
{
	if(NULL == num){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_IPHOST_NUM,num);
}

/******************************************************************************
 Descriptor:    It's used to set video UNI slot.
 Input Args:    onuSlot: omciOnuSlot_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_onu_slot(omciOnuSlot_t *onuSlot)
{
	return set_omci_cfg_data(SHARED_ONU_SLOT,onuSlot);
}

/******************************************************************************
 Descriptor:    It's used to get video UNI slot.
 Input Args:    onuSlot: omciOnuSlot_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_onu_slot(omciOnuSlot_t *onuSlot)
{
	if(NULL == onuSlot){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_ONU_SLOT,onuSlot);
}


/******************************************************************************
 Descriptor:    It's used to get FILE transfer control message.
 Input Args:    fileCtrl: file_transfer_ctrl_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_pptp_video_ani_cfg(pptp_video_ani_t *pptpVideoAniCfg)
{
    if(NULL == pptpVideoAniCfg){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_VIDEO_ANI_CFG,pptpVideoAniCfg);
}
/******************************************************************************
 Descriptor:    It's used to set FILE transfer control  message.
 Input Args:    fileCtrl: file_transfer_ctrl_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_pptp_video_ani_cfg(pptp_video_ani_t *pptpVideoAniCfg)
{
    return set_omci_cfg_data(SHARED_VIDEO_ANI_CFG,pptpVideoAniCfg);
}

/******************************************************************************
 Descriptor:    It's used to get mib data sync init value.
 Input Args:    syncVal: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_mib_data_sync_init_val(uint8_t * syncVal)
{
	if(syncVal ==NULL){
		RETURN_FAIL_MSG("input param is null\n");
	}

	return get_omci_internal_data(SHARED_MIB_DATA_SYNC_INIT,syncVal);
}

/******************************************************************************
 Descriptor:    It's used to set mib data sync init value.
 Input Args:    syncVal: char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_mib_data_sync_init_val(uint8_t syncVal)
{
	return set_omci_internal_data(SHARED_MIB_DATA_SYNC_INIT,&syncVal);
}

/******************************************************************************
 Descriptor:    It's used to set all config data.
 Input Args:    cfg_data_ptr: config data structure.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_cfg_data(omci_cfg_data_t * cfg_data)
{
	int ret = 0;
	if(NULL == cfg_data){
		RETURN_FAIL_MSG("input param is null\n");
	}
	ret = set_omci_cfg_data(SHARED_ALL_DATA,cfg_data);
	if ( ret != 0){
		RETURN_FAIL_MSG("set SHARED_ALL_DATA fail!\n");
	}else{
		omci_lib_cfg_data_done();
	}
	return ret;
}


/******************************************************************************
 Descriptor:    It's used to get all config data.
 Input Args:    cfg_data_ptr: config data structure.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_cfg_data(omci_cfg_data_t * cfg_data_ptr)
{
	if(NULL == cfg_data_ptr){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_ALL_DATA,cfg_data_ptr);
}

/******************************************************************************
 Descriptor:    It's used to set SysUpTimeFunc.
 Input Args:    SysUpTimeFunc: unsigned int.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_sys_up_time(unsigned int SysUpTimeFunc)
{
	return set_omci_cfg_data(SHARED_SYS_UP_TIME,&SysUpTimeFunc);
}

/******************************************************************************
 Descriptor:    It's used to get SysUpTimeFunc.
 Input Args:    SysUpTimeFunc: unsigned int pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_sys_up_time(unsigned int *SysUpTimeFunc)
{
	if(NULL == SysUpTimeFunc){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_SYS_UP_TIME,SysUpTimeFunc);
}

/******************************************************************************
 Descriptor:    It's used to set authentication security methold.
 Input Args:    authSecurityMeth: auth_security_meth_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_auth_security_meth(auth_security_meth_t *authSecurityMeth)
{
    return set_omci_cfg_data(SHARED_AUTH_METH,authSecurityMeth);
}

/******************************************************************************
 Descriptor:    It's used to get authentication security methold.
 Input Args:    authSecurityMeth: auth_security_meth_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_auth_security_meth(auth_security_meth_t *authSecurityMeth)
{
    if(NULL == authSecurityMeth){
		RETURN_FAIL_MSG("input param is null\n");
	}
	return get_omci_cfg_data(SHARED_AUTH_METH,authSecurityMeth);
}

/******************************************************************************
 Descriptor:    It's used to enable/disable vlan filter data ME config IPHost.
 Input Args:    compileOption: unsigned char.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_vlan_filter_iphost_en(char *flag)
{
    if(flag ==NULL){
        RETURN_FAIL_MSG("input param is null\n");
    }

    return get_omci_internal_data(SHARED_VLAN_FILTER_IPHOST_EN,flag);
}

/******************************************************************************
 Descriptor:    It's used to get if vlan filter data ME can config IPHost .
 Input Args:    timeStatusMsg: time_status_msg_t pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_vlan_filter_iphost_en(char flag)
{
    return set_omci_internal_data(SHARED_VLAN_FILTER_IPHOST_EN,&flag);
}

/******************************************************************************
 Descriptor:    It's used to get UPStream AES key mode.
 Input Args:    mode: unsigned char pointer.
 Ret Value: success: OMCI_LIB_SUCCESS
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_get_onu_up_AES_mode(unsigned char *mode)
{
    if(mode ==NULL){
        RETURN_FAIL_MSG("input param is null\n");
    }

    return get_omci_internal_data(SHARED_UP_AES_MODE,mode);
}

/******************************************************************************
 Descriptor:    It's used to set UPStream AES key mode.
 Input Args:    mode: unsigned char pointer.
 Ret Value: success: UPStream AES key mode
               fail: OMCI_LIB_FAIL
******************************************************************************/
int omci_lib_set_onu_up_AES_mode(unsigned char mode)
{
    return set_omci_internal_data(SHARED_UP_AES_MODE,&mode);
}

